Android - Save ImageView to file with full resolution image

ⅰ亾dé卋堺 提交于 2019-12-05 16:37:15

You could hold a Bitmap Object in Background, which you can resize with this piece of code:

Matrix matrix = new Matrix();
matrix.postScale(scaledWidth, scaledHeight);

Bitmap resizedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0,
    originalBitmap.width(), originalBitmap.height(), matrix, true); 

And save it later using this code:

OutputStream fOut = null;
File file = new File(strDirectoy,imgname);
fOut = new FileOutputStream(file);

resizedBitmap.compress(Bitmap.CompressFormat.PNG, 0, fOut);
fOut.flush();
fOut.close();

My solution was to use the matrix that I used for the ImageView to get the translation and I also had the scale of that image. Using those two I cropped the original image.

Bitmap resizedBitmap = Bitmap.createBitmap(
                        BitmapFrontCover, (int) UpperLeftCornerX,
                        (int) UpperLeftCornerY, (int) CropWidth,
                        (int) CropHeight);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!