burhanrashid52 / PhotoEditor

A Photo Editor library with simple, easy support for image editing using paints,text,filters,emoji and Sticker like stories.
MIT License
4.12k stars 989 forks source link

Scaling issue when loading images by network #397

Closed jsericksk closed 2 years ago

jsericksk commented 2 years ago

When I try to load an image with some image library, the image behaves differently than normal. This issue also occurs when using an image stored on the device. setImageResource() is the only no that has this problem, when the image is loaded locally in res/drawable.

Using the Coil library: photoEditorView.source.load(imageUrl). The same happens with photoEditorView.source.setImageURI(URI) and photoEditorView.source.setImageBitmap(Bitmap):

Screenshot_1632165451

Using photoEditorView.source.load(resource):

Screenshot_1632165482

Changing the scale type with photoEditorView.source.scaleType has no effect.

jsericksk commented 2 years ago

I noticed that setting the image directly with the library can solve this problem, depending on the library used. With Glide: Glide.with(context).load(imageUrl).centerInside().into(photoEditorView.source)

I didn't get the same behavior with Coil, which is my focus. Even though the ImageView has a scaleType defined before, Coil apparently doesn't use it. Alternatively, as a workaround, I set a size to be used when loading the image. This way, the image has the usual appearance of a FIT_CENTER scale.

photoEditorView.source.load(imageUrl) {
    size(2000)
}
github-actions[bot] commented 2 years ago

This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 5 days with no activity.

aintiqaa-technologies commented 3 months ago

mPhotoEditorView.source.scaleType = ImageView.ScaleType.CENTER_CROP

fun loadImage(imgURL: Uri?, errorThumb: Int?, imgView: PhotoEditorView?,mMeasuredWidth:Int) {
imgView?.source?.load(imgURL) {
placeholder(errorThumb ?: 0)
error(errorThumb ?: 0)
memoryCachePolicy(CachePolicy.ENABLED)
allowHardware(false)
size(mMeasuredWidth)
}
}

This worked in my case I am using Coil to load Image