如何从Image知道ImageFormat? [英] How to know ImageFormat from Image?
本文介绍了如何从Image知道ImageFormat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发掌上电脑.
我有一个公共属性,属性为[EditorBrowsable()].
当我尝试将* .ico格式加载到Image并调用某些功能时,我在GDI +中收到错误消息.如何在设计时从OpenFileDialog中排除* .ico格式或从Image中获取ImageFormat?
对不起,我的英语.
thx.
I develop pocket pc.
I have a public property with attribute .
When I try to load *.ico format into Image and summon some function I get an error in GDI+. How to exclude *.ico format from OpenFileDialog in Design-time or get ImageFormat from Image?
Sorry for my English.
thx.
推荐答案
文件对话框具有 ^ ]属性,该属性允许您排除不需要的任何文件类型.如果将其设置为仅显示图像类型的文件(例如,bmp
,jpg
和png
),则可以确定它返回的文件路径在使用加载时不会引起问题.Image
类.
使用Image.FromFile
或类似的东西加载文件时,最好在调用周围放置try - catch
,以防图像有效.这应该可以尝试将Icon
(或其他内容)加载到Image
的情况.
File Dialogs have a Filter[^] property that allows you to exclude any file types that you don''t want. If you set it to only show files of image types (bmp
,jpg
, andpng
for example) then you can be fairly sure that the file path it returns won''t cause problems when you load it using theImage
class.
When loading a file usingImage.FromFile
or something equivalent it''s always good to put atry - catch
around the call just in case the image is valid. That should catch the case of trying to load anIcon
(or something else) into anImage
.
我知道.但是,如何在设计时间上的OpenFileDialog上设置过滤器?
I know that. But how to set filter on OpenFileDialog in Design time?
这篇关于如何从Image知道ImageFormat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文