Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy image to internal memory

Tags:

android

How I copy a image to internal memory and recover after that?

like image 792
Alex Avatar asked May 23 '26 12:05

Alex


1 Answers

You can use the following combination of openFileOutput() and Bitmap.compress() to store the image to the internal storage.

// Create a BitMap object of the image to be worked with
final Bitmap bm = BitmapFactory.decodeStream( ..some image.. );

// The openfileOutput() method creates a file on the phone/internal storage in the context of your application 
final FileOutputStream fos = openFileOutput("my_new_image.jpg", Context.MODE_PRIVATE);

// Use the compress method on the BitMap object to write image to the OutputStream
bm.compress(CompressFormat.JPEG, 90, fos);
like image 82
Elijah Cornell Avatar answered May 25 '26 03:05

Elijah Cornell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!