简体   繁体   English

从像素列表创建Gtk.Image

[英]Creating a Gtk.Image from a pixel list

I am working on a GTK program that manipulates an image based on user input. 我正在研究一个GTK程序,该程序可根据用户输入来操纵图像。 I am using pypng to read the image and am now looking for a way to create a Gtk.Image from a pixel list without creating an intermediate image file. 我正在使用pypng读取图像,现在正在寻找一种从像素列表创建Gtk.Image而不创建中间图像文件的方法。

Not entirely easy to do in Python directly. 直接在Python中做并非完全容易。 You could do this, using GtkImage , which can load images from a GdkPixbuf.Pixbuf using a method called from_pixdata() . 您可以使用GtkImage做到这GtkImage ,它可以使用名为from_pixdata()的方法从GdkPixbuf.Pixbuf加载图像。

A higher level of doing this is using (for example) the PIL (in python2 ) or Pillow ( python3 ) . 更高级别的操作是使用(例如) PIL (在python2 )或Pillow (在python3 There, you can construct images using the Image module and the P IL.Image.frombytes() , PIL.Image.fromstring() , and other methods. 在这里,您可以使用Image模块以及P IL.Image.frombytes()PIL.Image.fromstring()和其他方法来构造图像。

There are also functions in matplotlib which convert arrays immediately to images. matplotlib中还有一些将数组立即转换为图像的函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM