Issue with loading very high resolution (15000 x 8438) image with glide - android

I am trying to load very high resolution image (15000 x 8438) with glide and saving it as bitmap.
I am using glide for that. The problem is that when I try to save bitmap image to file I get black image instead of actual image.
I feel maybe this is because of very high resolution. After converting to bitmap these values I have obtained: width 15000 height: 8438 getAllocationInBytes : 506280000.
I tried to downscale image with .downsample(DownsampleStrategy.AT_MOST) but image is still 15000 x 8438.
The code I am using is:
Glide.with(this).asBitmap()
.load(imagePath)
.downsample(DownsampleStrategy.AT_MOST)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(FileTarget(someFile, Bitmap.CompressFormat.JPEG, 90) {}
Can someone please help, how can I down scale the image and save it to the file. Also is it possible to achieve it with glide ?
Thank you.

To make downsample works as expected, you probably forgot to add the maxWidth and maxHeight override:
....
.downsample(DownsampleStrategy.AT_MOST)
.override(maxWidth, maxHeight)
...

Related

Picasso and Coil inconsistency in image sizing?

The first screenshot is with Picasso, the second one with Coil (both in latest versions). Any idea why is this happening?
Picasso: fit().centerInside()
Coil: scale(Scale.FILL).crossfade(true) (I tried with FIT also, same results)
ImageView: adjustViewBounds = true; scaleType = CENTER_INSIDE with MATCH_PARENT width and constant height in pixels.
Coil automatically adjusts to the scale type of the ImageView so you don't need to configure the scale.
Picasso does not, and Picasso's .fit().centerInside() is actually not equivalent to ImageView's CENTER_INSIDE but to FIT_CENTER (it will enlarge the image so that at least one dimension matches the ImageView). There is no equivalent to CENTER_INSIDE with Picasso but these are the closest options:
You can simply remove .fit().centerInside() and let the ImageView scale down the image if it's larger, but if the image is very large it will consume a lot of memory (and may fail to load if larger than the max texture size of the device).
You can use .resize(width, height).centerInside().onlyScaleDown() after measuring the size of the ImageView manually.
If you want Coil to resize the image the same way Picasso does with .fit().centerInside(), then just change the scale type of the ImageView to FIT_CENTER.

Images are blurry when rotate the screen android device with Glide

I use glide to load the drawable image in the adapter (the error occurred with the image not located in recyclerview):
Glide.with (holder.ivPreview) .load (mThemeDrawableIds.get (position)).into (holder.ivPreview)
When recording mThemeDrawableIds will be reloaded and notify again. However, the image is blurred compared to the original image.
I tried clearing the cache but the result is still the same.
It might help to also add android:adjustViewBounds="true" to your ImageView in XML.
Also try this code :
Glide.with(imageView).load(mThemeDrawableIds.get (position))
.apply(new RequestOptions()
.fitCenter()
.format(DecodeFormat.PREFER_ARGB_8888)
.override(Target.SIZE_ORIGINAL))
.into(holder.ivPreview);

Android Glide placeholder size the same with different image size

I spent all day for this issue :(
In my Android application, I download the images with different size from the server. For example, Image A has 500x330 size, Image B has 500x700 size and so on. I also added some text below the images. I am using a placeholder image with 500x400 size.
I can load the images and show placeholder by using Glide:
XML:
<android.support.v7.widget.AppCompatImageView
android:id="#+id/myImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
Kotlin:
GlideApp.with(myImage.context)
.load(url)
.skipMemoryCache(false)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(myImage)
Issue:
While the image is loading, the placeholder is shown with 400 height. When finish loading, users will see changes height from 400 to 700 for example. Then users also see that the text below the images are jumping up or down depend on the image size:(
Question:
How can I scale or keep the placeholder the same size with every loading images which I want to show on the UI. So that the UI does not change after loading?
Notes: I don't want to hard code the height of my images static like this layout_height="100dp". They should be kept the same size and radio as they are.
If Glide cannot do that. Do you guys have any other suggestions?
Thank you so much.
Don't know if this issue is still active. I hope it will help you if you set fitCenter() to Glide. This will fit the image into the placeholder and not change the dimensions. Buuut....you will see that there will be some white space if the photo doesn't have the exact aspect ratio as the placeholder image.
If it's not working as you want, you can try also to override the width and the height of the whole imageView by setting the width and the height of the placeholder image.
.override(w, h) // set exact size
.fitCenter() // keep memory usage low by fitting into (w x h) [optional]
where
w = placeholderDrawable width
h = placeholderDrawable height
I really hope this helps.
More details here

android glide into(Target) OOM

I am using Glide frame to load a picture, I want to set the height and the width of it, and I know what is the width I want, but how can I set the height of it.
what I have tried is blow,and I got an error of OOM. waiting for help, thanks.
if you want change size
Glide
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.override(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio
.into(imageViewResize);
Reference
Using override method of glide you can set the dimension of image in pixels.
Glide
.with(context)
.load(url)
.override(50 , 50)
.into(imageview);

Picasso center image without resizing into ImageView

I've come across this simple problem with the Picasso library. I haven't find any way to put an image into ImageView center it like android:ScaleType="center" does without cropping. Do you have any ideas about how to solve this ? My problem is that I don't know at the runtime the height and width of the BitMap I download so I can't use resize() properly.
This is a little late, but for anyone who's looking for a solution :
Picasso
.with(context)
.load(ImageURL)
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(imageViewFit);
If your ImageView is fixed one dimension and flexible another dimension (ex. android:width="match_parent", android:height="wrap_content"), you should be able to use android:adjustViewBounds="true" to get the ImageView to resize to display your image without cropping.
i am not found fit to center without resizing,
Picasso.get()
.load(source).resize(1650,700)
.centerCrop(Gravity.CENTER).into(imageView, new Callback()

Categories

Resources