Prachi
Prachi

Reputation: 2559

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 Regards

Upvotes: 1

Views: 3794

Answers (2)

Erfan Bagheri
Erfan Bagheri

Reputation: 638

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

Upvotes: 0

Aleadam
Aleadam

Reputation: 40401

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)

Upvotes: 5

Related Questions