1

I am working on vb.net windows application.
I have a picture in my 6th Cell of data grid view. I want to save that image in database.
So I write code like this:

Dim ms As New MemoryStream()
Dim imgCon As New ImageConverter
ms.Read(imgCon.ConvertTo(gv.Rows(0).Cells(6).Value, GetType(Byte())), 0, 1024)
Dim data As Byte() = ms.GetBuffer()

But here my image is not converting Byte array? How I can convert my data grid view image to byte array? Any help is very appreciable.

1 Answer 1

1

Get the image from the DataGridView and save the image into a memory stream. Write the stream content to byte array. My VB is little rusty so I have given the sample code in C#

Sample code:

Image image = myDGV.Rows[rowIndex].Cells[columnIndex].Value as Image;
if(image != null)
{
    MemoryStream ms = new MemoryStream();
    image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
    byte[] imagedata = ms.ToArray();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.