0

当我在 Linux 下使用 pylab 和 python 来绘制和显示图像时,如下例所示:

img = pylab.imread(filename)
pylab.imshow(img)
pylab.show()
pylab.draw()

当我这样做时,会弹出一个带有图像的新窗口。

我的问题:我如何影响位置和大小?

4

1 回答 1

1

The whole point of pylab's Image stuff is that you get a np.array of pixel data.

So, you can just do this:

img = pylab.imread(filename)
img = img * myTransformationMatrix
pylab.imshow(img)

If that immediately tells you what you need to know, great. If you don't understand what matrix multiplication has to do with rotating, translating, and scaling images, pylab is probably not the image library you want to use. Just use PIL.

If you're trying to manipulate the windows, rather than the images, pylab is really not meant for that.

You probably want to use TkInter, the windowing library that comes built-in with Python. It's can be ugly, clunky, and slow, and some advanced uses are either impossible or require you to write Tcl code instead of Python… but for simple stuff, it's not going to be a step down from pylab. In fact, it's what pylab uses under the covers.

If you start to hit the limits of TkInter, it's time to look at an external windowing library. You can go with a full GUI framework like Gtk+, Qt, or wx. The Python bindings to the three aren't that different; the important difference is that in the slightly different models of how GUIs work, so read about them and pick the model you like best. Alternatively, you can use something like pygame, which does very bare-bones windowing (the kind of thing games would need, rather than, say, word processors).

于 2012-12-12T19:38:48.160 回答