hi i'm trying to save picture downloaded in device storage i have this methods for save pictures in storage but after saved i find that the picture quality is bad please help me i want to save the picture with the same orignal quality
Glide.with(mContext)
.load("YOUR_URL")
.asBitmap()
.into(new SimpleTarget<Bitmap>(100,100) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
saveImage(resource);
}});
private String saveImage(Bitmap image) {
String savedImagePath = null;
String imageFileName = "JPEG_" + "FILE_NAME" + ".jpg";
File storageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
+ "/YOUR_FOLDER_NAME");
boolean success = true;
if (!storageDir.exists()) {
success = storageDir.mkdirs();
}
if (success) {
File imageFile = new File(storageDir, imageFileName);
savedImagePath = imageFile.getAbsolutePath();
try {
OutputStream fOut = new FileOutputStream(imageFile);
image.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
// Add the image to the system gallery
galleryAddPic(savedImagePath);
Toast.makeText(mContext, "IMAGE SAVED"), Toast.LENGTH_LONG).show();
}
return savedImagePath;
}
private void galleryAddPic(String imagePath) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(imagePath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);
}
This line:
.into(new SimpleTarget<Bitmap>(100,100)
Literally means that you want the image with a width of 100px and height of 100px, which is really really small, and i'm 99.99% sure this is what you mean with "bad quality".
If you want the 100% original image, you should use this:
.into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
"Target" is a class within Glide, and it has the "SIZE_ORIGINAL" constant.
That'll give you the full image, in original quality, which you can then save.