Object not initialised exception

wildfire1982

Regular
Joined
Oct 23, 2003
Messages
50
Location
Southampton
Hello folks.

I have made a small function which uses an image type. Im assuming that the exception is that the object is not instatiated but thats me attempting to translate from a german operating system. If my translation is right i understand what the problem is, i just cant see it. Here is the code.

Visual Basic:
        Dim cmdlg1 As New SaveFileDialog
        Dim filename As String
        Dim Images As Image
        cmdlg1.ShowDialog()
        filename = cmdlg1.FileName
        Clipboard.SetDataObject(AxMSChart1)
        'AxMSChart1.EditCopy()
        Dim piccy As New PictureBox
        Images.Save(filename)

The error occurs on the very last line. Any pointers would be great, cheers
 
Sorry i new i had missed a line when i cut and pasted it. this is the line which gets the image from the clipboard
it comes directly before the saving to file line.

Images = Clipboard.GetDataObject.GetData(DataFormats.EnhancedMetafile, True)
 
Right, i managed it. If anyone is interested it was because i needed to use an IDataObject to cast into.

One minor problem now. I can save to a bmp file only but the bitmap doesnt appear to be writing in format acceptable to windows. I have no idea why. Any ideas?
 
Ok sorted it. Just for future reference, or if anyone is interested. The problem was that i was using the default parameters for the image.save so i needed to include the format again in the save method as bmp otherwise it wrote rubbish to the .bmp file. so:

Visual Basic:
If filename.EndsWith(".bmp".ToLower) Then
            PictureBox1.Image.Save(filename, PictureBox1.Image.RawFormat.Bmp)
        End If
 
Back
Top