6

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

1 Answer 1

1

Use AndroidBmpUtil as shown in the code below:

new AndroidBmpUtil().save(bmImage, file);
Sign up to request clarification or add additional context in comments.

3 Comments

That makes the image size even bigger; 232KB :(
How to use this class ?
java.nio.BufferOverflowException crash in that class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.