How to save image

D

DapDap

I have manage to open a image into a picture box. But I
have problem in Saving it into database SQL Server. How
to save the image ??
 
G

Guest

I have gone threw this tutorial. But when I retrieve the image from the DB.
The image is only 1B, and I cannot open it. The filename is correct.

Whats wrong here?
 
K

Ken Tucker [MVP]

Hi,

You have to store the image in binary format. Storeimage converts
image to binary format. ConvertToBitmap converts it back. Note the offset
for the northwind database is 78 my storeimage function has a offset of 0.

Private Function StoreImage(ByVal bm As Bitmap) As Object

Dim ms As New MemoryStream

Try

bm.Save(ms, Imaging.ImageFormat.Jpeg)

Return ms.GetBuffer

Catch

Return Convert.DBNull

End Try

End Function

Private Function ConvertToBitmap(ByVal data() As Byte, ByVal offset As
Integer) As Bitmap

Dim ms As New System.IO.MemoryStream

Dim bm As Bitmap

ms = New MemoryStream

ms.Write(data, offset, data.Length - offset)

bm = New Bitmap(ms)

Return bm

End Function

Ken

----------------------

I have gone threw this tutorial. But when I retrieve the image from the DB.
The image is only 1B, and I cannot open it. The filename is correct.

Whats wrong here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top