Pick image from sd card, resize the image and save it back to sd card

前端 未结 6 1345
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 14:11

I am working on an application, in which I need to pick an image from sd card and show it in image view. Now I want the user to decrease/increase its width by c

6条回答
  •  北海茫月
    2020-12-13 14:44

    Try using this method:

    public static Bitmap scaleBitmap(Bitmap bitmapToScale, float newWidth, float newHeight) {   
    if(bitmapToScale == null)
        return null;
    //get the original width and height
    int width = bitmapToScale.getWidth();
    int height = bitmapToScale.getHeight();
    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    
    // resize the bit map
    matrix.postScale(newWidth / width, newHeight / height);
    
    // recreate the new Bitmap and set it back
    return Bitmap.createBitmap(bitmapToScale, 0, 0, bitmapToScale.getWidth(), bitmapToScale.getHeight(), matrix, true);  
    } 
    

提交回复
热议问题