读书人

wxpython知道文件的路径如何确定是否

发布时间: 2013-07-08 14:13:00 作者: rapoo

wxpython知道文件的路径,怎么确定是否是图片
如题。。


dialog = wx.lib.imagebrowser.ImageDialog(self, None)
if(dialog.ShowModal() == wx.ID_OK):
self.directory = dialog.GetFile()

由self.directory怎么知道这个文件是不是图片。。我不想要逐个图片格式的测试。。。 wxPython Python
[解决办法]
python有imghdr模块做这个事,见http://docs.python.org/2/library/imghdr.html。

引自上面的文档
The imghdr module determines the type of image contained in a file or byte stream.

The imghdr module defines the following function:

imghdr.what(filename[, h])

Tests the image data contained in the file named by filename, and returns a string describing the image type. If optional h is provided, the filename is ignored and h is assumed to contain the byte stream to test.

The following image types are recognized, as listed below with the return value from what():
Value Image format
'rgb' SGI ImgLib Files
'gif' GIF 87a and 89a Files
'pbm' Portable Bitmap Files
'pgm' Portable Graymap Files
'ppm' Portable Pixmap Files
'tiff' TIFF Files
'rast' Sun Raster Files
'xbm' X Bitmap Files
'jpeg' JPEG data in JFIF or Exif formats
'bmp' BMP files
'png' Portable Network Graphics

读书人网 >perl python

热点推荐