Search code examples
pythonkivy

How to render a large image in kivy without it looking pixilated


I'm trying to render pictures in my windows gui using kivy box layout i want to display the image without it taking the whole screen and still keeping its quality

I've tried taking the image original height and width then halfing it, it still looks weird.

Here is what a part of my code looks like:

from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivy.uix.image import Image
from kivy.uix.filechooser import FileChooserIconView
from kivymd.uix.relativelayout import MDRelativeLayout


RootLayout = MDRelativeLayout(md_bg_color=(1,1,0,1))

top_layout = MDBoxLayout(md_bg_color=(1,0,0,1), size_hint=1,.2),pos_hint={'top':1})
RootLayout.add_widget(top_layout)

left_layout = MDBoxLayout(md_bg_color=(1,.5,0,1),size_hint=(.26,.8),pos_hint={'left':1})
RootLayout.add_widget(left_layout)

middle_layout = MDBoxLayout(md_bg_color=(1,0,.5,1),size_hint=(.44,.8),pos_hint={'right':.7})
class fileExplorerKivy(FileChooserIconView):
    def on_selection(self,*args):
        img.source = args[1][0]
        img.allow_stretch=True

middle_layout.add_widget(fileExplorerKivy())
RootLayout.add_widget(middle_layout)

right_layout = MDBoxLayout(md_bg_color=(1,1,.5,1), size_hint=(.3,.8),pos_hint={'right':1})
RootLayout.add_widget(right_layout)
img = Image()
right_layout.add_widget(img)
class Explorer(MDApp):
    def build(self):
        return RootLayout

Explorer().run()

Here is what i want it to look like:
Here is what i want it to look like:

Here is what mine looks like:
Here is what mine looks like:


Solution

  • The reason your code is not producing the results you want, is because you never told Image to use mipmaps.

    This is literally all you have to do. However, the filter suggestion I made earlier should still be kept in your pocket because, even though you may think it looks clean, there are likely Moire' patterns everywhere. Both of our images are white, which makes it really hard to tell. I am unsure if Kivy automatically applies a filter, and even if it does, it might not be the one you want.

    img = Image(mipmap=True)
    

    enter image description here