Created
October 12, 2014 22:46
-
-
Save snadjafi/7a605d9ee4811c7bb84a to your computer and use it in GitHub Desktop.
flipping and save the photo if you take a photo using front camera
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
| @Override protected PatientPhoto doInBackground(PatientPhoto... intakePhotos) { | |
| PatientPhoto photo = intakePhotos[0]; | |
| File file = null; | |
| if (photo != null) { | |
| Matrix matrix = flip(new Matrix()); | |
| Bitmap bitmap = BitmapFactory.decodeByteArray(photo.getPhotoBytes(), 0, photo.getPhotoBytes().length); | |
| Bitmap flipped = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); | |
| photo.setThumbnail(ThumbnailUtils.extractThumbnail(flipped, 250, 250)); | |
| ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
| flipped.compress(Bitmap.CompressFormat.JPEG, 100, out); | |
| byte[] flippedByteArray = out.toByteArray(); | |
| file = CameraUtil | |
| .createExternalStoragePrivateFile(context, flippedByteArray, photo.getName()); | |
| photo.setFile(file); | |
| photo.setPhotoBytes(flippedByteArray); | |
| bitmap.recycle(); | |
| } | |
| if (file != null) { | |
| return photo; | |
| } else { | |
| return null; | |
| } | |
| } | |
| private Matrix flip(Matrix input) { | |
| float[] mirrorY = {-1, 0, 0, 0, 1, 0, 0, 0, 1}; | |
| Matrix matrixMirrorY = new Matrix(); | |
| matrixMirrorY.setValues(mirrorY); | |
| input.postConcat(matrixMirrorY); | |
| return (input); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment