且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用单个图像动态调整图像大小而不降低使用ASP.NET的图像质量

更新时间:2023-02-13 21:52:37

如果原始图像很好,这就叫做重新采样并且总是会降低质量质量。但是,如果缩小图像,质量问题可能非常小,但相比之下,如果将其放大,结果非常难看,通常是不可接受的。如果生成的图像太小也一样。



使用分形压缩可以获得一些放大效果,但这项技术是通常无法访问: http://en.wikipedia.org/wiki/Fractal_compression [ ^ ]。



调整图片大小.NET很简单。您只需打开原始位图,创建新位图并在新位图上绘制原始位图,使用适当的 System.Drawing.Graphics.DrawImage 方法将其缩放到目标大小:

http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage.aspx[^]。



使用此构造函数从目标位图获取用于绘制的类 System.Drawing.Graphics 的实例:http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx [ ^ ] 。



就是这样。



-SA

How to dynamically resize the Image using single Image without decreasing the quality of image using ASP.NET

For eg: I want to allow the user to download the Image into different resolution. but i have single image. and want to resize the image according to the selected size in dropdown list.

Please provide the solution as soon as possible....
Thank you in advance...!

This is called resampling and always reduce the quality, if the original image is of good quality. However, if you scale the image down, the quality problem can be very minor, but, in contrast, if you scale it up, results are quite ugly, usually unacceptable. Same thing if the resulting image is too small.

Some good results in enlargements can be obtained by using fractal compression, but this technology is not commonly accessible: http://en.wikipedia.org/wiki/Fractal_compression[^].

Resizing of images in .NET is easy. You only need to open original bitmap, create a new bitmap and draw the original bitmap on the new bitmap scaling it to the target size using appropriate System.Drawing.Graphics.DrawImage method:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage.aspx[^].

The instance of the class System.Drawing.Graphics for drawing is obtained from the target bitmap using this constructor: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx[^].

That''s it.

—SA