You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an image stored in the sdcard whose dimension is 300 x 300. I try to load it using the code below and try to resize it but the loaded image has its original size.
File file = new File("sdcard/image.jpg");
Glide.with(this).load(Uri.fromFile(file)).asBitmap()
.into(new SimpleTarget<Bitmap>(105, 105) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
Log.i("MainActivity", "Bitmap Dimen : " + resource.getWidth()); // Excepting 105 but returns 300
// Do something with the resized sourceaa
}
});
Am I missing something here or doing something wrong ?
The text was updated successfully, but these errors were encountered:
Decoding/Downsampler read image from stream with inSampleSize
Transforming/BitmapTransformation take the Bitmap and match the exact target size
The decoding is always needed and is included in the flow, the default case is to match the target size with the "at least" downsampler, so when it comes to the transformation the image can be downsized more without quality loss (each pixel in the source will match at least 1.0 pixels and at most ~1.999 pixels) this can be controlled by asBitmap().at least|atMost|asIs|decoder(with downsampler)
The transformation and target size is automatic by default, but only when using a ViewTarget. When you load into an ImageView the size of that will be detected even when it has match_parent. Also if there's no explicit transformation there'll be one applied from scaleType. Thus results in a pixel perfect Bitmap for that image, meaning 1 pixel in Bitmap = 1 pixel on screen resulting in the best possible quality with the best memory usage and fast rendering (because there's no pixel mapping needed when drawing the image).
With a SimpleTarget you take on these responsibilities by providing a size on the constructor or via override() or implementing getSize if the sizing info is async-ly available only.
To fix your load add a transformation: .fitCenter|centerCrop(), your current applied transformation is .dontTransform()
I have an image stored in the sdcard whose dimension is 300 x 300. I try to load it using the code below and try to resize it but the loaded image has its original size.
Am I missing something here or doing something wrong ?
The text was updated successfully, but these errors were encountered: