如何在asp.net, c#中从数据库中下载图像

本文关键字:数据库 下载 图像 asp net | 更新日期: 2023-09-27 18:11:26

我将图像保存到数据库中作为二进制格式,而检索我将二进制格式转换为图像文件并显示。

byte[] picbin = (byte[])(binary data in datbase);
ImageConverter ic = new ImageConverter();
System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(picbin);`

并通过指定名称将img- variable保存到某个文件夹中。但是现在我需要能够为用户提供任何格式的特定图像的可下载选项,以便用户可以验证它那么实现这个的方法是什么呢

如何在asp.net, c#中从数据库中下载图像

将图像转换为其他格式:

// Save the image in JPEG format.
img.Save(@"C:'test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// Save the image in GIF format.
img.Save(@"C:'test.gif", System.Drawing.Imaging.ImageFormat.Gif);
// Save the image in PNG format.
img.Save(@"C:'test.png", System.Drawing.Imaging.ImageFormat.Png);    

检查如何:将图像从一种格式转换为另一种格式