I am pretty much newer in asp.net MVC. My core objective is to Convert the .tiff image to .jpeg format without saving as file. For that i call separate file(ex:gettiff.aspx) for showing .tiff image in browser.
What i have done? I was saved the multipage .tiff image into DB as blob.
What i need? Need to show that multipage .tiff image by converting to .Jpeg in View
What i successfully done? To convert single page .tiff image(File/Blob), i don't have any problem in conversion as .jpeg and viewed as well in VIEW
Where i stuck? To convert multipage .tiff image(File/Blob), i have problem during the conversion as .Jpeg and viewed as well in VIEW
Sample Code: C#: In gettiff.aspx file
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);
}
Convert Blob to Bitmap:
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;
}
}
Convert bitmap to bytearray (this will gives as .jpeg format)
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;
}
In View:
<img src="../GetTiffImage.aspx?batchImageId=@item.RefImgId&&ImgType=CBlob" width="150" height="100" style=" border:groove;border-color: #ff0000;" />
I need to convert as .jpeg and display only the first page from that multi page .tiff blob.
Problem occurred while saving the stream - "A generic error occurred in GDI+"
Anybody can help me...