Reputation: 49
I want to save an image that exist in picture box as a byte array to the database.I am new to programming so please help me to resolve this. Everytime I save my image byte array in the database, it always shows the same byte array. 0x53797374656D2E427974655B5D
but this is what I see always in the database. No matter which image I save, it will always saves this code: 0x53797374656D2E427974655B5D
. Please help me to resolve this issue.
This is my code
Byte[] imgBytes = null;
ImageConverter imgConverter = new ImageConverter();
imgBytes =
(System.Byte[])imgConverter.ConvertTo(PictureBox1.Image,Type.GetType("System.Byte[]"));
Upvotes: 2
Views: 481
Reputation: 27011
To save an image, use Image.Save
ImageConverter is not for converting image to binary.
var stream = new MemoryStream();
PictureBox1.Image.Save(stream, ImageFormat.Png);
byte[] data = stream.ToArray();
Upvotes: 5