Picturebox Problems... 
Author Message
 Picturebox Problems...

I use the following function to load an image into a picturebox: (ImgPre is my picturebox)

    Function LoadImage(ByVal FullPath As String)
        'Varibles
        Dim bmp As Bitmap
        Dim owidth
        Dim oheight
        Dim nwidth
        Dim nheight
        Dim aspect

        'Load Image To Memory
        bmp = Bitmap.FromFile(FullPath)

        'Get Sizes / Aspect
        owidth = bmp.Width
        oheight = bmp.Height
        aspect = oheight / owidth

        'Get New Sizes
        nwidth = 350
        nheight = 350 * (aspect)

        'Update
        ImgPre.Height = nheight
        ImgPre.SizeMode = PictureBoxSizeMode.Normal
        ImgPre.Image = Nothing
        Me.Update()

        'Load Into ImgPre
        Dim rect As New RectangleF(0, 0, nwidth, nheight)
        ImgPre.CreateGraphics.DrawImage(bmp, rect)

        'Unload From Memory
        bmp.Dispose()
    End Function

I use this line of code to save the image loaded into the picturebox:

    ImgPre.Image.Save(fName, System.Drawing.Imaging.ImageFormat.Jpeg)

I get this error on the line above:

    Object reference not set to an instance of an object.

What would be causing this?  I have a feeling it has something to do with the Image in the picturebox but I cannot figure it out.

Thanks-

Matt

--
Matt MacLean
__________



Mon, 31 Jan 2005 14:24:13 GMT  
 Picturebox Problems...
In your loadimage function you destruct the ImgPre.image

   ImgPre.Image = Nothing

And in this line you refer to the object that is set to nothing :

 ImgPre.Image.Save(fName, System.Drawing.Imaging.ImageFormat.Jpeg)

That will create the error you are getting.

Do you at all see the image in the picturebox  ??

Allan



Mon, 31 Jan 2005 14:56:08 GMT  
 Picturebox Problems...
Yes.. The image is shown i the picture box no problem. The ImgPre.Image = Nothing is called before
the DrawImage so that shouldn't do anything.

Thanks

Quote:

> In your loadimage function you destruct the ImgPre.image

>    ImgPre.Image = Nothing

> And in this line you refer to the object that is set to nothing :

>  ImgPre.Image.Save(fName, System.Drawing.Imaging.ImageFormat.Jpeg)

> That will create the error you are getting.

> Do you at all see the image in the picturebox  ??

> Allan



Tue, 01 Feb 2005 06:53:43 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. PictureBox problem

2. picturebox problem

3. Printing Image in Picturebox Problems

4. PictureBox Problem

5. picturebox problems

6. PictureBox Problem

7. PictureBox Problems

8. PictureBox problems

9. Saving PictureBox problem

10. PictureBox problem

11. Compiling VB5 Projects in Visual Studio VB6 - picturebox problem

12. Using DrawState API to Emboss a PictureBox - PROBLEMS

 

 
Powered by phpBB® Forum Software