I have a square image and I want to display it as background of a rounded rectangle. I want to avoid this image to be deformed. Here is a visual explanation of what I mean.
I tried to create a canvas and to set my image as the source of a RoundedRectangle to obtain the desired visual. Nevertheless the image is distorted to fit into the rectangle, which changes the ratio of the image. This is not what I want to obtain; is there a way to crop the image automatically? I tried to use the property fit_mode of Kivy 2.2 but it doesn't apply to RoundedRectangle.
Here is my Python file:
from kivy.app import Appfrom kivy.lang import Builderfrom kivy.uix.relativelayout import RelativeLayoutclass CustomImage(RelativeLayout): passclass MyScreen(RelativeLayout): passkv = Builder.load_file("draft_question.kv")class MyApp(App): def build(self): return kvif __name__ == "__main__": MyApp().run()Here is my .kv file:
#:kivy 2.2.1<CustomImage>: canvas.before: RoundedRectangle: pos: (0,0) size: self.size source: "image.jpg" radius: [40,] #fit_mode: "cover"MyScreen: CustomImage: size_hint: (0.6, 0.2) pos_hint: {"center_x": 0.5, "center_y": 0.5}Thank you in advance for your help!