Save/Open drawn image

dgdolins1

New member
Joined
Sep 29, 2003
Messages
3
Hi,

I have a picturebox on a form that I am able to draw on (similar to ms paint). My declarations are as follows:

Code:
    Globals
    Dim b As Drawing.Bitmap  Eventually initialzed to b = New Drawing.Bitmap(Me.Width, Me.Height)
    Dim g As Drawing.Graphics
    Dim pen As New Drawing.Pen(System.Drawing.Color.DarkBlue, 2)
    Dim aBgColor As Drawing.Color = Drawing.Color.White

I can sucessfully save the Image using the following code:
Code:
Public Sub SaveSigAsImage(ByVal Path As String)
        b.Save(Path)
End Sub

I can sucessfully open the image right when the program starts with the following code:
Code:
Public Sub OpenSigImage(ByVal Path As String)
        picSig.Image = Image.FromFile(Path)
        b = picSig.Image      
End Sub

The problem is, when I open an image, modify it and save it, an exception is thrown: An unhandled exception of type System.NullReferenceException occurred in WindowsApplication3.exe

Additional information: Object reference not set to an instance of an object.

The exception is thrown on the line b = picSig.Image in OpenSigImage.

How do I initialize b when opening the picture?

Thank you.
 
Last edited by a moderator:
Code:
DIM b as NEW drawing.bitmap

try it out... otherwise you could try

Code:
DIM b as drawing.bitmap

...(In your open image code)...

b = NEW drawing.bitmap(picSig.Image)
 
Hi,

Thanks for the response. I tried what you said and I was not able to get it working. If anyone would like to view the code, here it is. Its all in the usercontrol.

Thank you very much.
 

Attachments

Hi there.
I think u did not handle the image that uve open(happened to me once). Dont remember how i solve it already but i think it has something to do with the method u save it(couze image is still opening the file and b is trying to override it). try close image or set it to nothing. Hope it helps.
 
Back
Top