如何在.NET中减小为屏幕渲染优化的上载图像的大小? [英] How do I reduce the size of an uploaded image, optimized for screen rendering, in .NET?

查看:111
本文介绍了如何在.NET中减小为屏幕渲染优化的上载图像的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我要求接受从用户上传的图像(可能是用他们的数码相机拍摄的),以便随后在各个页面上呈现.我想找到图像质量和图像尺寸之间的平衡.

我知道我可以裁剪图像,并调整高度/宽度属性;但我主要担心的是,大多数数码相机在拍摄照片时都会考虑打印-而不是屏幕渲染.因此,当屏幕可能为96dpi时,我想避免使用300dpi的图像.如何在VB.NET中以编程方式减少这种情况?我相信它应该减小图像的文件大小,但不会对屏幕渲染质量产生不利影响.

另外,如何计算图像中独特颜色的数量并相应地减小颜色深度?我还想避免将图像设置为每个像素2400万种颜色,但实际上它的颜色深度小于第二个最低的颜色深度设置.

希望有道理.

预先感谢您的帮助.

解决方案

看看编码器类:

http://msdn.microsoft.com/en-us/library/64h235xe (v = VS.71).aspx [ http://www.glennjones.net/Post/799/Highqualitydynamicallyresizedimageswithnet.htm [ ^ ]

祝您好运!


只需添加,DPI无关紧要,Windows不在乎它,HTML完全忽略了它.只有WPF尊重DPI,但即使如此,它只是文件中的一个数字,它是用于确定显示设备大小的细节,它不会更改文件的大小.与图像中的像素数无关.最好的选择是另存为JPEG,因为它有损,所以要小得多,但是它被设计成有损的方式,人眼不太可能注意到.计数颜色是一项艰巨的工作,但我想,如果将图像从24位减少到16位,那么我也会节省相当多的尺寸.


Hi all,

I have a requirement to accept images uploaded from users, probably taken with their digital cameras, for subsequent rendering on various pages. I want to find the balance between image quality and image size.

I know I can crop the image, and adjust the height/width properties; but my main concern is that most digital cameras take pictures with printing in mind - and not screen rendering. So I''d like to avoid and images at, say, 300dpi when the screen will probably be 96dpi. How do I programmatically reduce this in VB.NET? I believe it should reduce the file size of the image, but not adversely affect the screen rendered quality.

Also, how can I count the number of unique colours in an image and reduce the colour depth accordingly? I''d also like to avoid an image that''s set to 24 million colours per pixel, but actually has less than the next lowest colour depth setting.

Hope that makes sense.

Thanks in advance for your assistance.

解决方案

Have a look at the encoder class:

http://msdn.microsoft.com/en-us/library/64h235xe(v=VS.71).aspx[^]

For reducing the color depth it is much easier to let an compression algorithm take care of this. By the way, people would upload jpeg most of the time (a lot of camera''s store pictures as jpeg) and you wouldn''t benefit from reducing the colorspace. It''s the same as editing and storing an image to jpeg all the time, the quality would be reduced each time over and over.

Example code:
http://www.glennjones.net/Post/799/Highqualitydynamicallyresizedimageswithnet.htm[^]

Good luck!


Just to add, the DPI is irrelevant, windows doesn''t care about it, and it''s completely ignored by HTML. Only WPF respects DPI, but even then, it''s just a number in the file, it''s a detail used to determine size on a display device, it doesn''t change the file size b/c it''s unrelated to how many pixels are in the image. Your best bet is to save as a JPEG, which is a lot smaller because it is lossy, but it''s designed to be lossy in ways that the human eye is less likely to notice. It''s a lot of work to count the colors, but if you reduce an image to 16 bit from 24, you will get a fair size saving, too, I''d think.


这篇关于如何在.NET中减小为屏幕渲染优化的上载图像的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆