日期:2014-05-20  浏览次数:20714 次

关于png和jpeg图像格式的问题
public   Bitmap   _image;
  _image   =   SeismicMap._sectionImage   ;
    _image.Save(Response.OutputStream,   imageformat.png);

以上,_image内存有一副图片,以上述代码将此图像以指定的格式保存到流中,问题是为什么png格式会报错,而jpeg格式没问题,但是我要做无损压缩,所以想用png格式,另外,jpeg格式有1-10种(我记不太清楚了)不同的压缩格式,这个该怎么调整呢,在c#中

------解决方案--------------------
up
------解决方案--------------------
http://www.microsoft.com/china/MSDN/library/archives/library/DNAspp/html/colorquant.asp

http://blog.csdn.net/syqqman/archive/2006/05/15/729177.aspx
------解决方案--------------------
jpeg也可以无损,指定最高质量就可以了
------解决方案--------------------
维也纳升的好快
------解决方案--------------------

------解决方案--------------------
沒有這樣用過 ,都是向文件或內存流輸出。樓主指定 image/png 了嗎?

而且你是在網頁上輸出指定最高質量的JPEG已經足夠了。肉眼是看不出差別的。
------解决方案--------------------
任何时候都应该先写入MemoryStream对象,在用MemoryStream写入Response.OutputStream
------解决方案--------------------

那就不知道什么异常了,检查一下程序吧,可能是错误在图形的绘制过程中..
------解决方案--------------------
jf
------解决方案--------------------
up
------解决方案--------------------
我刚刚试过了,先写入内存流,再输出的方法是可行的。如果这样都不可行,那真的没道理可讲了。

另外:
Png 's are a special case. Their encoder requires a bi-directional stream. The solution is to stream to a memory stream first and write the contents of that memory stream to OutputStream afterwards.

When you get to caching (which I 've just implemented) you 'll be writing to a memory stream anyway just to cache the output, so this isn 't a big deal.

As far as the GIF end of things goes, the default palletization of the built in GIF encoder leaves something to be desired. I 've built in support for an Octree quantizer to deal with this.