Gtk + 3 Gdk Pixbuf.new_from_data给出“分段错误(核心已转储)"错误139 [英] Gtk+3 Gdk Pixbuf.new_from_data gives "Segmentation fault (core dumped)" error 139
问题描述
在我的应用程序中,我有一个GtkImage,它必须显示所选文件中的处理后图像.因此,在处理程序部分中,我有:
In my application I have a GtkImage that must show the processed image from a choosed file. So, in the handlers section I have:
import numpy as np
from PIL import Image , ImageDraw
from gi.repository import Gtk, GdkPixbuf
. . .
. . .
def on_fitchooserdialog_response(self, menuitem, data=None):
if data == 1:
self.fitlist = self.fitchooser.get_filenames()
# get data from 1st file:
_, self.data = Getdata(self.fitlist[0])
# convert from Fits to 2D array:
pngarray = Fit2png(self.data)
# rescale:
size = tuple(x/2 for x in pngarray.shape)
im = Image.fromarray(pngarray)
im.thumbnail((size[1],size[0]), Image.BICUBIC)
到这里,一切都OK.如果我们这样做:
Up to here, all is OK. If we do:
im.save("../tmp/tmp.png")
pixbuf = GdkPixbuf.Pixbuf.new_from_file('../tmp/tmp.png')
self.imagen.set_property("pixbuf", pixbuf)
期望的图像粘贴在GtkImage小部件上. 但这是丑陋的方式吗?
the expected image is pasted on the GtkImage widget. But that is the ugly way, isnt it?
所以我正在尝试:
im = im.convert("RGB")
arr = np.array(im).flatten()
pixbuf = GdkPixbuf.Pixbuf.new_from_data(arr,
GdkPixbuf.Colorspace.RGB, False, 8, size[1], size[0], 3*size[1])
但是结果是错误139,分段错误(核心已转储)"
But the result is "Error 139, Segmentation fault (core dumped)"
我想念什么?
推荐答案
这似乎与以下gdk错误有关: https://bugzilla.gnome.org/show_bug.cgi?id=721497
This seems to be related to this gdk bug: https://bugzilla.gnome.org/show_bug.cgi?id=721497
基本上,这是gdk的python包装程序中的免费bug使用后,它可能会像对您造成的那样导致图像变形和/或段错误. 请参阅: https://stackoverflow.com/a/24070152/3528174
Basically it is a use after free bug in the python wrapper of gdk which can result in image distortions and/or segfaults as it did for you. See: https://stackoverflow.com/a/24070152/3528174
You can find an example of such image distortions in this question: How to correctly covert 3d array into continguous rgb bytes
这篇关于Gtk + 3 Gdk Pixbuf.new_from_data给出“分段错误(核心已转储)"错误139的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!