c#图像缩放质量在开发环境和生产环境之间有所不同

编程入门 行业动态 更新时间:2024-10-27 08:26:52
本文介绍了c#图像缩放质量在开发环境和生产环境之间有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个功能,该功能可以调整图片大小和裁剪,然后保存生成的图像文件.在我的开发环境中,它工作得很好,但是在生产中,最终的图像是颗粒状的".您可以在此处 test.powersport.it/canc2.aspx

i have created a function that resizes and crops a picture and then saves the resulting image file. In my development environment it works just great, but on production the resulting image is "grainy". You can see the different quality here test.powersport.it/canc2.aspx

这是生成调整大小和裁剪图像的代码

Here is the code that generates the resized and cropped image

// width: width of cropped img - height: height of cropped img System.Drawing.Bitmap thumbnail = new Bitmap(width, height); // image: original System.Drawing.Image containing full size img thumbnail.SetResolution(image.HorizontalResolution, image.VerticalResolution); // size[0]: width of resized img - size[1]: height of resized image System.Drawing.Image mini = new Bitmap(image, size[0], size[1]); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(thumbnail); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.DrawImage(mini, ((width - size[0]) / 2), ((height - size[1]) / 2), size[0], size[1]); EncoderParameters encoderParameters; encoderParameters = new EncoderParameters(1); ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders(); // img: original file name switch (Path.GetExtension(img).ToLower()) { case ".png": // info[4] thumbnail.Save(dest, System.Drawing.Imaging.ImageFormat.Png); break; case ".bmp": // info[0] thumbnail.Save(dest, System.Drawing.Imaging.ImageFormat.Bmp); break; case ".tiff": // info[3] encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionLZW); thumbnail.Save(dest, info[3], encoderParameters); break; case ".tif": // info[3] encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionLZW); thumbnail.Save(dest, info[3], encoderParameters); break; default: //jpeg info[1] encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, compression); thumbnail.Save(dest, info[1], encoderParameters); break; }

感谢您的帮助.谢谢.

更新:我已经尝试过PNG,BMP和TIFF,但是它们存在相同的问题

UPDATE: i've tried with PNG, BMP and TIFF but they have the same problem

推荐答案

您假设每台机器在完全相同的索引处都具有完全相同的编码器.

很可能每台计算机实际上都以不同的格式压缩图像,尽管有文件扩展名.

You're assuming that each machine has exactly the same encoders at exactly the same indexes.

It's likely each machine is actually compressing images in a different format, depspite the file extension.

WS2008和WS2008 R2具有不同的图形子系统.在后者中,GDI +只是WIC编码器的包装,WIC编码器具有不同的怪癖.

WS2008 and WS2008 R2 have different graphics subsystems. In the latter, GDI+ is just a wrapper for the WIC encoders, which have a different sent of quirks.

我真的希望您决定使用可为您处理这些差异的库.服务器端映像既不简单也不直观,并且有无数的陷阱清单避免.除了您在这里遇到的编码问题之外,.NET似乎实际上会从 System.Drawing 命名空间中垃圾收集类.不会,除非每个引用都在 using(){} 子句内,否则您将遇到一些严重的稳定性问题.

I really hope you decide to use a library that handles these differences for you. Server-side imaging is neither simple nor intuitive, and has an endless list of pitfalls to avoid. Aside from the encoding issues you're having here, it looks like you're under the impression .NET will actually garbage collect classes from the System.Drawing namespace. It won't, and you're going to have some serious stability issues unless every reference is inside a using(){} clause.

更多推荐

c#图像缩放质量在开发环境和生产环境之间有所不同

本文发布于:2023-11-17 06:00:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609079.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   有所不同   缩放   图像   质量

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!