Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
ui.ImageView contents not cropping to View bounds
-
I have a
ui.ImageView
withcontent_mode = ui.CONTENT_SCALE_ASPECT_FILL
. The documentation implies that using this content mode will crop the parts of the image that fall outside the bounds of theImageView
.ui.CONTENT_SCALE_ASPECT_FILL
Scale the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.However, the excess image simply overflows outside the bounds of the
View
, spilling over other elements, making me sad.Two questions:
- Is this a bug? Or is this the expected functionality of
ui.CONTENT_SCALE_ASPECT_FILL
? - If this is indeed the intended behavior, how do you crop a
ui.Image
simply?
Regarding question 2, I've gotten cropping to work using the
PIL.Image.crop()
, and converting that croppedPIL.Image
into aui.Image
, but this is expensive, and I need these images to be loaded quickly in real-time. - Is this a bug? Or is this the expected functionality of
-
@iAmMortos be careful, you say ...FIT and you give the doc of ...FILL
But, you are right, this is a new bug, not existing in the past, with ui.CONTENT_SCALE_ASPECT_FILL
-
Oops. I goofed writing the post. But in my code, I am indeed using
ui.CONTENT_SCALE_ASPECT_FILL
. I've updated my original post. -
@iAmMortos Finally, I think it has always been like that. You need to use an intermediate View
-
This I can do! Thanks for the tip!
-
There is an attribute, maybe only in objc, clipstoBounds, which defines whether a views contents spill out past the edge of it's bounds. I forget if the python ui.Views have clips_to_bounds.
-
@JonB never seen in Pythonista UI, not in the doc.
-
It’s a uiView property, supposed to regulate the behavior of a view’s subviews.
Instance Property clipsToBounds A Boolean value that determines whether subviews are confined to the bounds of the view.
-
@iAmMortos, Views clip to their bounds by default, but for some reason ImageView does not, which explains some behaviour I did not understand previously, thanks.
As others have said, you can fix this without extra views with:
iv.objc_instance.setClipsToBounds_(True)