Groups | Blog | Home
all groups > dotnet drawing api > april 2006 >

dotnet drawing api : Want Gif, but got PNG


Liming
4/6/2006 9:36:15 AM
Hi all,

I have a byte[] and I'm trying to stream it back to my aspx page using
Resposne.OutputStream

I set the content-type to "image/gif".. but when I stream it back, I
got a png instead.

here is a watered down version

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "image/gif";
string disheader = "inline; filename=\"" + myinfo.FileName + "\"";
HttpContext.Current.Response.AppendHeader("Content-Disposition",
disheader);


byte[] btImage1 = myservice.OctreeQuantize(bImage1);

HttpContext.Current.Response.BinaryWrite(bImage1);


This produce a png image on the web page.

So I tried to convert the byte array back to a bitmap and then save to
a gif explicilty...

MemoryStream ms = new MemoryStream();
ms.Write(btImage1,0,btImage1.Length);
Bitmap bmp = null;
bmp = new Bitmap(ms);
bmp.Save(HttpContext.Current.Response.OutputStream,ImageFormat.Gif);

but the problem with this apporach is that suddenly, the GIF looks all
chopped up.

So basically, what's wrong with these two approaches I have? How can I
stream back the byte array directly to the OutputStream and at the same
time, speicificy it as a gif? Why is content-type not doing anything?

Thanks
Liming
4/6/2006 2:28:21 PM
problemo solved. Before I return back the byte[] from
myservice.OctTreeQuantize() method, in the method, I need to FIRST,
save it as ImageFormat.GIF into a memeoryStream and then convert to
byte[] and return it back. If you don't specific ImageFormat.GIF
before you convert it to a byte[], somehow, .net framework takes png i
guess.

Hope it's helpful to others.
AddThis Social Bookmark Button