1

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 Regards

Prachi
  • 2,559
  • 4
  • 25
  • 37

2 Answers2

5

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:

These are methods of the View class, so they are applicable to any derived one (including ImageView)

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108
0

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();
Erfan Bagheri
  • 638
  • 1
  • 8
  • 16