I am developing a function that downloads.JPG image from the Internet.
When I download using BitmapFactory.decodeStream()
and save it in my internal storage, the file size is bigger than the original file.
The original image file(.JPG) size is 114KB and the size of the file what I saved is 261KB
b = BitmapFactory.decodeStream(urlConnection.getInputStream()); //Download original image
FileOutputStream fos = openFileOutput("x.jpg", MODE_PRIVATE);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
File ne = new File(getFilesDir()+"/x.jpg");
String l = ""+ Formatter.formatFileSize(MainActivity.this,ne.length())+"byte"//261KB
edit:
InputStream is = urlConnection.getInputStream();
OutputStream outStream = MainActivity.this.openFileOutput("x.jpg", MODE_PRIVATE);
byte[] buf = new byte[1024]; int len = 0;
int total_len=0;
while ((len = is.read(buf)) > 0) {
outStream.write(buf, 0, len);
total_len+=len;
}
is.close(); outStream.close();
//total_len = 116797 byte
//saved image file size = 116797 byte
Bitmap z = BitmapFactory.decodeFile(getFilesDir()+"/x.jpg");
img.setImageBitmap(z);