Show Image
-
Hi all i have some code above. I have Some problem when i save this image is type Gif/ JPG so this image show but when i save is PNG is not yet And when i check C:\\demo.Png is Exist and open is ok but on web is not ok. ???? byte[] byImg = objimg.getBytes(); using (MemoryStream objStream = new MemoryStream(byImg)) { System.Drawing.Image img = System.Drawing.Image.FromStream(objStream); Bitmap bp = (Bitmap)img; //Check this image can show bp.Save("C:\\demo.Png", System.Drawing.Imaging.ImageFormat.Png); // Show image bp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); }
-
Hi all i have some code above. I have Some problem when i save this image is type Gif/ JPG so this image show but when i save is PNG is not yet And when i check C:\\demo.Png is Exist and open is ok but on web is not ok. ???? byte[] byImg = objimg.getBytes(); using (MemoryStream objStream = new MemoryStream(byImg)) { System.Drawing.Image img = System.Drawing.Image.FromStream(objStream); Bitmap bp = (Bitmap)img; //Check this image can show bp.Save("C:\\demo.Png", System.Drawing.Imaging.ImageFormat.Png); // Show image bp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); }
Problem is the format of PNG is not compatible with the Response.OutputStream method directly, you need to store the image in a memorystream at then send that to the browser... System.IO.MemoryStream memStream; byte[] bytBuffer; Response.Clear(); Response.ContentType = "image/png"; memStream = new System.IO.MemoryStream(); bp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); bytBuffer = memStream.ToArray(); Response.OutputStream.Write(bytBuffer, 0, bytBuffer.Length); Response.End(); My C++ skills not good, this is a translation of the VB.NET code that I use.. :-D