Click here to Skip to main content
14,487,047 members
Rate this:
Please Sign up or sign in to vote.
The scenario is that I have a Visual Basic .NET form with a picturebox on it. The image for this box can come from a file (gif) or from Inkpicture strokes. The gif file was originally created from another Inkpicture stroke.

Once input and accepted, this Image is then transferred into a dataset byte array which is then used in a rdlc report displaying as a database input gif image on the final report.

All is good provided the picturebox image is created from a file, however if it is created from a memory stream/byte array or any other memory based instance, although image in the picturebox is perfect and scaled to fit the size of the picture box, when displayed in the rdlc report it comes up as a black box or could this be an inverse or encrypted box of the true image?

The question is why does it work with a file input and not with a memory input? The mechanism to transfer the picture box to the rdlc report is identical in both cases, its just how the data enters the Picturebox.

Why not leave it as a file input I hear you say? Well its because Picturebox locks the file so you cannot edited/save back to file until the link between the picturebox and file is cleared. I occasionally wish to Inkpicture edit the image which you cannot do once it is linked to the file.


What I have tried:

'Code to enter data from the file is( No Problem) :
PictureBox1.Image = Image.FromFile(“filename”)

'Code to enter data directly from InkPicture from (has issue) :
Dim imgBytes() As Byte
imgBytes = dialogue.InkPicture1.Ink.Save(PersistenceFormat.Gif, CompressionMode.Maximum) 
  Using MS As New MemoryStream(imgBytes)
    PictureBox1.Image = Image.FromStream(MS)
 End Using

'Code to enter data into the PictureBox while trying to keep file unlocked (has the issue):

PictureBox1.Image = DirectCast(Image.FromFile(“Filename”.Clone, Image)

'OR

 PictureBox1.Image = New Bitmap(Image.FromFile(“filename”))

'OR

Dim BitM As Bitmap = Bitmap.FromFile(“Filename”)
PictureBox1.Image = New Bitmap(BitM)
BitM.Dispose()


'Common Code to put the file into the dataset
'save picturebox image to datatable if available
If PictureBox1.Image IsNot Nothing Then
   Using MS As New MemoryStream()
    Try
       PictureBox1.Image.Save(MS, Imaging.ImageFormat.Gif)
       Dim imgBytes As Byte() = MS.ToArray()
       dsNewRow.Item("Picture") = imgBytes
     Catch ex As Exception
       MessageBox.Show("Exception raised with putting Picture in dataset")
     End Try
    End Using
End If
DatasetForm.Tables("MyTable").Rows.Add(dsNewRow)
Posted

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100