tags:

views:

56

answers:

3

Hello, I am retrieving an image from the SQL database into Byte() variable in vb.net

Dim img as byte()=dr(0)

How do I create a file in my C:\images\ directory from the above img.

I want to read the img and then create a file with name bimage.gif

Please help

A: 

Try:

Dim ms as MemoryStream = New MemoryStream(img)
Dim bmp as Bitmap = CType(Bitmap.FromStream(ms), Bitmap)

bmp.Save(@"C:\images\name.gif", ImageFormat.Gif);

bmp.Dispose()
ms.Dispose()
Steve Danner
+1  A: 

The easiest way is to use File.WriteAllBytes

Dim img as byte()=dr(0)
File.WriteAllBytes("C:/images/whatever.gif", img)
Sam
It's still weird to me how forward slashes work the same as backslashes in Windows now (unless it's always been that way).
MusiGenesis
@MusiGenesis, agreed, afaik not everything supports forward slashes, but .NET does and they doesn't require escaping.
Sam
A: 

System.IO.File.WriteAllBytes(@"c:\whatever.txt", bytes)

MusiGenesis