优化调整图像

时间:2017-11-02 03:41:37

标签: c# fiddler

希望这是一个有效的问题。我了解C#的方式,但我绝对不是效率最高的代码。我在服务器上运行Fiddler作为代理服务器来调整图像大小。这基本上模糊了移动设备上的所有图像。

有没有办法使用PNG作为格式并以更有效的方式执行此操作?或者至少有一个很好的方法来测试大量数据,这样我可以提高效率吗?

var oStream = new MemoryStream(oSession.responseBodyBytes);
var oBMP = new Bitmap(oStream);
oStream.Dispose();

var height = oBMP.Height;
var width = oBMP.Width;
oBMP = (Bitmap)oBMP.GetThumbnailImage(15, 15, null, IntPtr.Zero);
oBMP = (Bitmap)oBMP.GetThumbnailImage(width, height,null, IntPtr.Zero);

var oNewStream = new MemoryStream();

oBMP.Save(oNewStream, ImageFormat.Png);
oBMP.Dispose();

oSession.responseBodyBytes = oNewStream.GetBuffer();
oNewStream.Dispose();
oSession.oResponse.headers["Content-Length"] = oSession.responseBodyBytes.Length.ToString();
oSession.oResponse.headers["Content-Type"] = "image/png";
oSession.oResponse.headers["Cache-Control"] = "no-cache";

TL; DR在C#中大量模糊图像的处理器密集程度最低?

0 个答案:

没有答案