简体   繁体   中英

Image byte array is not saving properly

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[]"));

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM