Android - Save ImageView to file with full resolution image

限于喜欢 提交于 2019-12-07 11:02:39

问题


I put an image inside an ImageView and have multitouch implemented to resize and move the image inside the ImageView. Now I need to save the resized image to a image file. I have tried the .getDrawingCache() but that image have the size of the ImageView. I want the image to show what the ImageView shows but with full resolution (larger than the ImageView).

Any ideas?


回答1:


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();



回答2:


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);


来源:https://stackoverflow.com/questions/8643759/android-save-imageview-to-file-with-full-resolution-image

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