Dim
Dim

Reputation: 453

Cant convert image to bytearray

I am trying to convert a picturebox in byte array

MemoryStream s = new MemoryStream();
picProfilePicture.Image.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic = s.ToArray();

But when i am using this method i am getting general error in GDI+. How can i fix that?

Upvotes: 0

Views: 48

Answers (1)

Gaurav
Gaurav

Reputation: 623

    FileStream fs = new FileStream(selectedFile, FileMode.Open, FileAccess.Read);
    byte[] bimage = new byte[fs.Length];
    fs.Read(bimage, 0, Convert.ToInt32(fs.Length));

Upvotes: 1

Related Questions