Groups | Blog | Home
all groups > dotnet drawing api > december 2003 >

dotnet drawing api : trouble creating an image from an array of bytes


NP
12/31/2003 5:47:41 PM
I am trying to create an image from an array of bytes stored in a
base64binary dataset field and I keep getting the same error: System
argument exception. Invalid parameter used.
The field definitely contains an image because it is obtained from an image
file and placed into the database.
The error occurs on the third line. The overloaded constructor of the bitmap
class can accept a stream object and "m" is a memorystream object that
inherits from stream, so I don't see why it would not work.
Any suggestions?

Here's one of the attempts I made (VB.Net):

Dim b() As Byte = Me.dtDataSet.t_mytable(0).mypicture
Dim m As New System.IO.MemoryStream(b)
Dim Img As New Bitmap(m)

JHornick NO[at]SPAM online.microsoft.com
1/2/2004 5:42:39 PM
Hi,

Try storing the bytes into a file - then you can inspect the file
and ensure it contains reasonable image bits for whatever format
image file you've saved.

Keep in mind that this constructor assumes the bytes are in the same
format as the contents of an image file. So if you have just image
bits in DIB format, you'll need to use a different constructor then
copy the image bits to Scan0.

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.




[quoted text, click to view]
NP
1/5/2004 1:39:56 PM
Thanks. I'll try your suggestion.

[quoted text, click to view]

AddThis Social Bookmark Button