Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
MIDL
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!
Posted
Comments
johannesnestler 2-Dec-10 17:57pm    
what does the exception tell you? can you debug the code? maybe Picturebox1 is null or the image? should be easy solvable... beginner?

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:
C#
Picturebox1.Load( Application.StartupPath  + "\\targetImage.jpg");
            sm = new SecurityManagement(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:
C#
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" );
}
 
Share this answer
 
v4
You could try setting the Image property directly, using Image.FromStream()[^], preferably (rather than Image.FromFile()).
 
Share this answer
 
Comments
Rajesh Anuhya 3-Dec-10 2:00am    
Good Call

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900