显示图像 [英] Displaying image

查看:62
本文介绍了显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试使用以下代码在对话框中显示图像;


Dim frm As new frmImage

Dim z As System.Drawing.Bitmap

z.FromFile(" c:\ temp\image.gif")

frm.picImage.Image = z

frm.ShowDialog()

frm.Dispose()


麻烦就是那个对话框中不显示任何图像。我做错了什么?


谢谢


问候

解决方案

PS:picImage是一个PictureBox。


" John" <乔** @ nospam.infovis.co.uk>在留言中写道

新闻:Ox ************** @ TK2MSFTNGP09.phx.gbl ...



我正在尝试使用以下代码在对话框中显示图像;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile(" c:\ temp\image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

麻烦的是对话框中没有图像出现。我做错了什么?

感谢



" John" ; <乔** @ nospam.infovis.co.uk>在新闻中写道:OxEaex3kDHA.1284

@ TK2MSFTNGP09.phx.gbl:

我试图使用以下代码在对话框中显示图像;

Dim frm As new frmImage
Dim z As System.Drawing.Bitmap

z.FromFile(" c:\ temp\ image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

麻烦的是对话框中没有图像出现。我做错了什么?




我认为你并没有表明编译器是什么?b $ b如果你真的失败了意思是


z = Image.FromFile(" c:\ temp\image.gif");


但还有另一个错误。我认为你的文件名中有你的

反斜杠的问题......一般情况下,你应该在使用之前检查

变量。在调用FromFile()之后,我会把'z''

的假设付出来。要解决此问题,请将以下任一行替换为




z = Image.FromFile(@c:\ temp \ image.gif) ;


(@告诉编译器不要解释''\''字符),或者


z = Image.FromFile( c:\\temp\\mage.gif")

-mbray


Evening John ,


在Image = z行上放置一个断点并检查z的值。你会发现它没什么。


z.FromFile()正在调用< shared>方法。它与调用

Bitmap.FromFile(..)相同。换句话说,它不会(不能)改变z。


您需要的是:

Dim z As System.Drawing。位图

z = Bitmap.FromFile(" c:\ temp\image.gif")

或简单地

Dim z As New System.Drawing.Bitmap(" c:\ temp \ image.gif")

问候,

Fergus

Hi

I am trying to display an image in a dialog using the following code;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile("c:\temp\image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

Trouble is that no image appears in the dialog. What am I doing wrong?

Thanks

Regards

解决方案

PS: picImage is a PictureBox.

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...

Hi

I am trying to display an image in a dialog using the following code;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile("c:\temp\image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

Trouble is that no image appears in the dialog. What am I doing wrong?

Thanks

Regards



"John" <jo**@nospam.infovis.co.uk> wrote in news:OxEaex3kDHA.1284
@TK2MSFTNGP09.phx.gbl:

I am trying to display an image in a dialog using the following code;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile("c:\temp\image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

Trouble is that no image appears in the dialog. What am I doing wrong?



I presume from the fact that you aren''t indicating that the compiler is
failing that you really mean

z = Image.FromFile("c:\temp\image.gif");

but there is another error. I think you are having a problem with your
backslashes in the filename... In general, you should always check a
variable before you use it. I would put money of the supposition that ''z''
is null after the call to FromFile(). To FIX the problem replace the line
with either:

z = Image.FromFile(@"c:\temp\image.gif");

(the @ tells the compiler not to interpret the ''\'' characters), OR

z = Image.FromFile("c:\\temp\\image.gif");

-mbray


Evening John,

Put a breakpoint on the Image = z line and check the value of z. You''ll
find that it''s Nothing.

z.FromFile() is calling a <shared> method. It''s the same as calling
Bitmap.FromFile(..). In other words it doesn''t (can''t) change z.

What you need is either:
Dim z As System.Drawing.Bitmap
z = Bitmap.FromFile("c:\temp\image.gif")
or simply
Dim z As New System.Drawing.Bitmap ("c:\temp\image.gif")

Regards,
Fergus


这篇关于显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆