Hot questions for Using Glide in image quality

Top 10 Java Open Source / Glide / image quality

Question:

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);
}

Answer:

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.

Question:

I build simple gallery. I load my photos using Glide. It looks like on images loaded by glide is some kind of streak (pixels seems to be visible). I tried to load photo with changed Format RGB_565/ARGB_8888 and I used .dontTransform() but still it looks worse than original photo.

Code I use to load :

ImageView photoDetails;
photoDetails = (ImageView)findViewById(R.id.imageDetails);
Glide.with(this)
        .load(pictureFile) //path to picture
        .asBitmap()
        .format(DecodeFormat.PREFER_ARGB_8888)
        .dontTransform()
        .into(photoDetails);

Answer:

To load the original image using Glide I use the code below:

  Glide.with(view.getContext())
                    .load(pictureFile)
                    .asBitmap()
                    .into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL) {
                        @Override
                        public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                            imageView.setImageBitmap(resource);
                        }
                    });

Remember that the picture in browser may look different on the device due to the screen resolution of your device. Using this method you will be able to check the pixels using the Bitmap object. Also, keep in mind that your ImageView must have width and height with WRAP_CONTENT value.