To save image from imageView in android
I have an image in image-view and i want to save image from image-view to gallery or any storage space can anyone tell me how to do this??? Thank you.
Best Reg开发者_JS百科ards
In short, you get the bitmap rom the drawing cache:
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
There are several questions here with answers showing full code:
Android take screenshot via code
How to programmatically take a screenshot in Android?
These are methods of the View class, so they are applicable to any derived one (including ImageView)
You could hold a Bitmap Object in Background 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();
精彩评论