acadia
acadia

Reputation: 2621

Creating a file based on the byte() in VB.NET

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.

Upvotes: 11

Views: 41334

Answers (3)

MusiGenesis
MusiGenesis

Reputation: 75296

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

Upvotes: 4

Samuel Neff
Samuel Neff

Reputation: 74909

The easiest way is to use File.WriteAllBytes

Dim img as byte()=dr(0)
File.WriteAllBytes("C:/images/whatever.gif", img)

Upvotes: 19

Steve Danner
Steve Danner

Reputation: 22158

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()

Upvotes: 2

Related Questions