我想将图片框中存在的图像作为字节数组保存到数据库。我是编程新手,所以请帮助我解决这个问题。每当我将图像字节数组保存在数据库中时,它总是显示相同的字节数组。0x53797374656D2E427974655B5D但这是我在数据库中始终看到的内容。无论我保存哪个图像,它都将始终保存以下代码:0x53797374656D2E427974655B5D。请帮助我解决此问题。
这是我的代码
Byte[] imgBytes = null;
ImageConverter imgConverter = new ImageConverter();
imgBytes =
(System.Byte[])imgConverter.ConvertTo(PictureBox1.Image,Type.GetType("System.Byte[]"));
Run Code Online (Sandbox Code Playgroud)
要保存图像,请使用Image.Save
ImageConverter不能用于将图像转换为二进制。
var stream = new MemoryStream();
PictureBox1.Image.Save(stream, ImageFormat.Png);
byte[] data = stream.ToArray();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
75 次 |
| 最近记录: |