Android Image Processing
Android image processing summary:
1: when taking a photo on Android, we may encounter some statuses. For example, if you take a photo on a Samsung mobile phone, the photo may be automatically rotated after the photo is taken, in this regard, the rotating photo is restored:
Bitmap bitmap = BitmapFactory. decodeFile (Const. ACT_CREATE_PIC_PATH.concat (photoName ));Int angle = imageUtils. getExifOrientation (Const. ACT_CREATE_PIC_PATH.concat (photoName ));If (angle! = 0) {// if the image is rotated, change the rotation level.Matrix matrix = new Matrix ();Matrix. postRotate (angle );Bitmap = Bitmap. createBitmap (bitmap, 0, 0, bitmap. getWidth (), bitmap. getHeight (), matrix, true );}
2: If the Android app needs to process and upload images, the image size is a big problem, because the photo taken by mainstream Android phones should be at least 3 m, if you need a filter or upload, it will take a lot of time. In fact, most of us do not need images of high quality. When the image resolution is high, it only works when you view the large image. on the mobile phone screen, you do not need images of high quality. Therefore, if you do not need to crop the image, you can reduce the image resolution proportionally. Sample Code:
public String scaleDown(String path,Context context){ Bitmap orignalB=BitmapFactory.decodeFile(path); float ratio = Math.min((float) 974 / orignalB.getWidth(),(float) 974 / orignalB.getHeight()); int width = Math.round((float) ratio * orignalB.getWidth()); int height = Math.round((float) ratio * orignalB.getHeight());Bitmap newB = Bitmap.createScaledBitmap(orignalB,width,height, true);String imgName=path.substring(path.lastIndexOf("/")+1,path.length()-1);String userId= UserHelper.getUserId(context);String newpath=createDirectoryAndSaveFile(newB,userId+System.currentTimeMillis()+".jpg");orignalB.recycle();newB.recycle(); return newpath;}