I've just imported the Picasso library in my project and I'm using it like described in this other SO question (I need to download & save some images from web server). The whole thing is working correctly except for a thing: the resulting image in my emulator is bigger (in terms of weight) than the original on server. For example, a JPG image of 52Kb (370 x 505 pixels), result in a JPG image of same resolution (370 x 505) but 132Kb of weight. This is the code I'm using (saw in a lot of SO questions):
if (target == null){
target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
new Thread(new Runnable() {
@Override
public void run() {
File file = new File(getActivity().getFilesDir() + "/saved.jpg");
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, ostream);
ostream.flush();
ostream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {}
};
}
Picasso.with(getActivity()).load(sourceValue).into(target);
Thanks you all in advance for your time and your attention.
UPDATE:
Checking the memory of my emulator, I've noticed that the cached version of the image that Picasso create, has the correct size. So, basically, if I use the same code I've posted, but I comment all the try-catch block, the file is just downloaded and cached (not saved in another location) but has the correct size. So it is compression's fault?