Piscean
Piscean

Reputation: 3079

Why size of image is not same when i download an image from a url?

I am downloading an image from a url and create a bitmap image in my android app. Size of image is 126 kb. When i create an image in my app by downloading it from url then size is around 3.25 mb. I am using following code to downlad image from url:

URL urlConnection = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) urlConnection.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(input);

Why downloaded size of image is bigger and is there any way to download it in the same size? Thanks in advance.

Upvotes: 0

Views: 716

Answers (4)

greenapps
greenapps

Reputation: 11224

Dont use Bitmapfactory for downloads. Use an InputStream and a FileOutputStream to save to internal, external or removable memory directly.

Upvotes: 1

QArea
QArea

Reputation: 4981

Android converts this image to bmp. You can convert it by youself and you get size ~3.5 mb.

Upvotes: 1

vjalex
vjalex

Reputation: 63

Image size depends on bits per pixel .during conversion you have to give bits per pixel file size is given by Resolution^2 x Width x Height x Bits per sample ÷ 8,192

Upvotes: 0

Okas
Okas

Reputation: 2674

Image you download is probably in some compressed format (.jpg .png). Bitmap you get from BitmapFactory.decodeStream on the other hand is in uncompressed format. If you dont need to show your bitmap in original resolution you can scale it down (detailed instructions here). Otherwise such memory usage is normal.

Upvotes: 1

Related Questions