FitImage#
Feature to automatically crop a Kivy image to fit your layout
Write by Benedikt Zwölfer Referene - https://gist.github.com/benni12er/95a45eb168fc33a4fcd2d545af692dadExample:#
MDBoxLayout:
size_hint_y: None
height: "200dp"
orientation: 'vertical'
FitImage:
size_hint_y: 3
source: 'images/img1.jpg'
FitImage:
size_hint_y: 1
source: 'images/img2.jpg'
MDBoxLayout(
FitImage(
size_hint_y=.3,
source='images/img1.jpg',
),
FitImage(
size_hint_y=.7,
source='images/img2.jpg',
),
size_hint_y=None,
height="200dp",
orientation='vertical',
)
Example with round corners:#
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
MDScreen:
MDCard:
radius: 36
md_bg_color: "grey"
pos_hint: {"center_x": .5, "center_y": .5}
size_hint: .4, .8
FitImage:
source: "bg.jpg"
size_hint_y: .35
pos_hint: {"top": 1}
radius: 36, 36, 0, 0
'''
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return Builder.load_string(KV)
Example().run()
from kivymd.app import MDApp
from kivymd.uix.card import MDCard
from kivymd.uix.fitimage import FitImage
from kivymd.uix.screen import MDScreen
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return (
MDScreen(
MDCard(
FitImage(
source="bg.jpg",
size_hint_y=0.35,
pos_hint={"top": 1},
radius=(36, 36, 0, 0),
),
radius=36,
md_bg_color="grey",
pos_hint={"center_x": .5, "center_y": .5},
size_hint=(0.4, 0.8),
),
)
)
Example().run()
API - kivymd.uix.fitimage.fitimage
#
- class kivymd.uix.fitimage.fitimage.FitImage(**kwargs)#
Fit image class.
For more information, see in the
MDLayout
andStencilBehavior
classes documentation.- source#
Filename/source of your image.
source
is aStringProperty
and defaults to None.
- mipmap#
Indicate if you want OpenGL mipmapping to be applied to the texture. Read Mipmapping for more information.
New in version 1.0.0.
mipmap
is aBooleanProperty
and defaults to False.
- reload(self)#