我在asp.net MVC中非常新颖。我的核心目标是将.tiff图像转换为.jpeg格式,而不保存为文件。为此我调用单独的文件(例如:gettiff.aspx)在浏览器中显示.tiff图像。如何使用C#将多页Blob .Tiff图像中的第一页转换并显示为.Jpeg#
我做了什么? 我将多页.tiff图像作为blob保存到数据库中。
我需要什么? 需要显示多页.tiff图像转换为.JPEG在查看
我成功地完成了什么? 要转换单页.tiff图像(文件/ Blob),我没有任何问题转换为.jpeg并查看以及在查看
我卡在哪里? 要转换多页.TIFF图像(文件/ BLOB),我有转换为.JPEG期间的问题,在图中观察以及
示例代码: C#:以gettiff.aspx文件
while (Reader.Read())
{
Bitmap bImage = ByteToImage((byte[])Reader["refImage"]);
byte[] array1 = ImageToByte2(myBmp);
Response.ContentType = "image/jpeg"; // if your image is a jpeg of course
Response.BinaryWrite((byte[])array1);
}
斑点转换为位图:
public static Bitmap ByteToImage(byte[] blob)
{
using (MemoryStream mStream = new MemoryStream())
{
mStream.Write(blob, 0, blob.Length);
mStream.Seek(0, SeekOrigin.Begin);
Bitmap bm = new Bitmap(mStream);
return bm;
}
}
转换位图以字节组(这将让作为.JPEG格式)
public static byte[] ImageToByte2(Bitmap img)
{
byte[] byteArray = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
//System.Drawing.Image.FromStream(stream);
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
byteArray = stream.ToArray();
}
return byteArray;
}
在View:
<img src="../[email protected]&&ImgType=CBlob" width="150" height="100" style=" border:groove;border-color: #ff0000;" />
我需要为JPEG格式转换,并从多页.TIFF BLOB只显示第一页。同时节省了流发生
问题 -
任何人都可以帮我“GDI +中发生一般性错误” ......