Last active
August 29, 2015 14:14
-
-
Save oak-tree/872010e8d29e59e9cb42 to your computer and use it in GitHub Desktop.
Android crop image - psudo code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PictureCallback myPictureCallback_JPG = new PictureCallback(){ | |
| @Override | |
| public void onPictureTaken(byte[] data, Camera arg1) { | |
| // TODO Auto-generated method stub | |
| try { | |
| private final INT_QUALITY = 2; | |
| BitmapFactory.Options options=new BitmapFactory.Options(); | |
| options.inSampleSize = INT_QUALITY; | |
| bitmapPicture = BitmapFactory.decodeByteArray(data, data.length,options); | |
| int dim = Math.min(bitmapPicture.getHeight(),bitmapPicture.getWidth()) | |
| bitmapPicture = Bitmap.createBitmap( | |
| bitmapPicture, | |
| 0, | |
| 0, | |
| dim, | |
| dim | |
| ); | |
| ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
| //create a file to write bitmap data | |
| File f = new File(context.getCacheDir(), filename); | |
| f.createNewFile(); | |
| //Convert bitmap to byte array | |
| Bitmap bitmap = your bitmap; | |
| ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
| bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos); | |
| byte[] bitmapdata = bos.toByteArray(); | |
| //write the bytes in file | |
| FileOutputStream fos = new FileOutputStream(f); | |
| fos.write(bitmapdata); | |
| fos.flush(); | |
| } catch (IOException e) { | |
| // do stuff | |
| } finally { | |
| if (fos != null) { | |
| fos.close(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment