imageLocation不会立即设置图片框的图像 [英] imageLocation does not set image of a picture box immediately

查看:137
本文介绍了imageLocation不会立即设置图片框的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Picturebox1.ImageLocation = Application.StartupPath  + "\\targetImage.jpg";
            sm = new SecurityManagement(Picturebox1.Image );



上面的代码,在执行第二行时收到空引用错误.
请建议我如何解决该问题.
谢谢!


Hi,
above, I receive the error of null reference while executing the second line.
Please suggest me how can I resolve the issue.
Thank You!

推荐答案

我认为设置ImageLocation属性只是分配路径,因此图像尚未加载到Picturebox1.Image属性中.请尝试以下操作:
I think setting the ImageLocation property just assigns the path, so the image is not loaded into the Picturebox1.Image property yet. Try the following:
Picturebox1.Load( Application.StartupPath  + "\\targetImage.jpg");
            sm = new SecurityManagement(Picturebox1.Image );


这将设置ImageLocation并导致图像显示,并将其加载到PictureBox1.Image属性中.

修改:

基于有关该问题的新规范,以下代码应能完成您要寻找的内容:


This will set the ImageLocation and cause the image to display, which will load it into the PictureBox1.Image property.

Modification:

Based on the new specifications regarding the problem, the following code should accomplish what you are looking for:

Bitmap bitmap;

private void button1_Click(object sender, EventArgs e)
{
    using ( FileStream tempbmp = new FileStream ( @"targetImage.jpg", FileMode.Open ) )
    {
        bitmap = ( Bitmap )Bitmap.FromStream ( tempbmp );
    }

    System.IO.File.Delete ( @"targetImage.jpg" );
}


您可以尝试使用 ^ ],最好是(而不是Image.FromFile()).
You could try setting the Image property directly, using Image.FromStream()[^], preferably (rather than Image.FromFile()).


这篇关于imageLocation不会立即设置图片框的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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