Python 在Kivy中创建自定义图像类,将mag_过滤器设置为;最近的;
我做错了什么?我无法让我的自定义图像类将mag_过滤器设置为“最近”。像素图像非常模糊,单独设置mag_过滤器很烦人 下面是我的Python:Python 在Kivy中创建自定义图像类,将mag_过滤器设置为;最近的;,python,python-3.x,opengl,kivy,kivy-language,Python,Python 3.x,Opengl,Kivy,Kivy Language,我做错了什么?我无法让我的自定义图像类将mag_过滤器设置为“最近”。像素图像非常模糊,单独设置mag_过滤器很烦人 下面是我的Python: #test2.py import kivy kivy.require("1.10.0") from kivy.app import App from kivy.lang import Builder from kivy.uix.boxlayout import BoxLayout from kivy.uix.image import Image cla
#test2.py
import kivy
kivy.require("1.10.0")
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
class Container(BoxLayout):
pass
class CustomImage(Image):
def build(self):
#self.ids.img.texture.mag_filter = 'nearest' #doesn't work
#self.img.texture.mag_filter = 'nearest' #doesn't work
self.texture.mag_filter = 'nearest' #doesn't work
#texture.mag_filter = 'nearest' #doesn't work
class TestName(App):
def build(self):
global root
Builder.load_file("picTest.kv")
root = Container()
return root
### Keep everything below this last! ###
if __name__ == '__main__':
TestName().run()
这是相应的Kivy文件
#picTest.kv
Container:
#Container holds all the other layouts
<Container>:
id: contain
CustomImage:
source: "smile.png"
CustomImage:
source: "smile.png"
CustomImage:
source: "smile.png"
<CustomImage>:
id: img
allow_stretch: True
#picTest.kv
容器:
#容器包含所有其他布局
:
id:包含
自定义图像:
资料来源:“smile.png”
自定义图像:
资料来源:“smile.png”
自定义图像:
资料来源:“smile.png”
:
id:img
允许拉伸:真
“smile.png”:
您必须通过绑定纹理来完成此操作,并且在回调中必须更改纹理,此连接必须在构造函数中完成
#test2.py
import kivy
kivy.require("1.10.0")
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
class Container(BoxLayout):
pass
class CustomImage(Image):
def __init__(self, *args, **kwargs):
Image.__init__(self, *args, **kwargs)
self.bind(texture=self._update_texture_filters)
def _update_texture_filters(self, image, texture):
texture.mag_filter = 'nearest'
class TestName(App):
def build(self):
Builder.load_file("picTest.kv")
root = Container()
return root
### Keep everything below this last! ###
if __name__ == '__main__':
TestName().run()
之前:
之后: