Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Save ImageView to file with full resolution image

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?

like image 386
ahrberg Avatar asked Dec 27 '11 10:12

ahrberg


2 Answers

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();
like image 122
kroegerama Avatar answered Sep 20 '22 01:09

kroegerama


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);
like image 32
ahrberg Avatar answered Sep 22 '22 01:09

ahrberg