5

The typical way (based on research) for saving bitmap images from a remote url is:

Bitmap bmImage = null;

InputStream in = new java.net.URL(imageUrl).openStream();
bmImage = BitmapFactory.decodeStream(in);

File file = new File(myPath);

FileOutputStream outputStream;
outputStream = new FileOutputStream(file);

bmImage.compress(Bitmap.CompressFormat.PNG, 100, outputStream);

outputStream.close();

I cannot save bitmap unless it is compressed (Bitmap is always uncompressed). The remote image size is 32KB, after compression it gets 110KB. I know I have to lower compression parameter to get smaller size, but the remote image is optimize and much more efficient.

Is there a way I can save the remote image on mobile storage without compressing it?

===== ANSWER TO MY PROBLEM =====

First I apologize for misleading content; all I wanted is to save images that could be png|jpeg|gif|etc.. Probably I mislead you guys that the image I am trying to save is in BMP format, but it is not.

Nevertheless, for those who want to save images WITHOUT compressing, have a look to this answer

Community
  • 1
  • 1
PeaceDefener
  • 618
  • 2
  • 8
  • 22

1 Answers1

1

Use AndroidBmpUtil as shown in the code below:

new AndroidBmpUtil().save(bmImage, file);
spenibus
  • 4,339
  • 11
  • 26
  • 35
Wayne Jo
  • 203
  • 1
  • 4