调整图片大小的基本知识或图片大小发生了什么? [英] Basics in Resizing Pictures or What happened to Picture Size ?

查看:136
本文介绍了调整图片大小的基本知识或图片大小发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我编写了一个程序来调整图片的大小,如下所示:

Hi,

I write a program that resize pictures like this:

Image originalImage = Image.FromFile(pathToOriginalPicture);
    
    Bitmap b = new Bitmap(newWidth, newHeight);
    Graphics g = Graphics.FromImage(b);
    
    g.DrawImage(originalImage, 0, 0, newWidth, newHeight);
    g.Dispose();
    
    b.Save(pathToOutputPicture, ImageFormat.Jpeg);


我尝试设置:


I tried to set:

newWidth = originalImage.Width;
    newHeight = originalImage.Height;


结果是经过重新整理的图片文件变为〜900K,而原始文件为〜4M.

为什么会这样?
原始图片的质量是否比调整后的图片好?在什么地方?

我在Photoshop中打开了两张图片,我看到原始图片是72ppi,而调整后的图片变成了96ppi.这是为什么 ?我可以控制吗?

非常感谢您的宝贵时间!


非常感谢您的回答!
我真的不想调整"到原始大小.
那只是一个例子.
实际上,我编写了一个程序来将图片的大小调整为所需的大小(以像素为单位的宽度和高度).
我注意到,即使图片大小减小了一点,文件的大小也减小了很多.我只是想了解为什么.
然后,我尝试将大小"调整为原始大小,并发现文件大小变得很小.这对我来说真的很奇怪!
我仍然不明白这种情况下的输出图片是否比原始图片差.
在我的程序中,我希望调整JPEG图片的大小,以便通过电子邮件发送它们.我知道有很多程序可以做到这一点,但是我想编写自己的程序.
您能否建议如何调整JPEG的大小,以使输出图片具有最高质量?
谢谢!


The result was that the rezised picture file became ~900K while the original file was ~4M.

Why this is happening ?
Is the quality of the original picture better than the resized one ? In what ?

I opened both pictures in Photoshop and I see that the original picture was 72ppi, while the resized one became 96ppi. Why is that ? Can I control this ?

Thanks a lot for your time !

Hi,
Thank you very much for your answers !
I don''t really want to "resize" to the original size.
That was just an example.
Actually, I write a program that resizes pictures to the desired size (width and height in pixels).
I''ve noticed that even if the picture size decreases a little, the file size decreases very much. I just want to understand why.
Then I tried to "resize" to the original size, and saw that the file size become pretty little. This is really strange to me !
I still don''t understand whether the output picture in this case is worse than the original picture.
In my program I''m interested to resize JPEG pictures in order to send them by email. I know that there are many programs that do that, but I want to write my own program.
Could you suggest how to resize JPEGs such that the output picture will be with highest quality ?
Thanks !

推荐答案

首先,为什么要调整"图像的大小以相同大小?

无论如何...我知道您的图片是jpeg.打开和保存jpeg几乎总是会失去质量.

您应该真正使用png代替.

其次,ppi,dpi或其他无关紧要的.这与质量无关,它既不影响文件大小也不影响屏幕视图质量.它仅影响打印尺寸.

如果愿意,可以尝试:
In the first place, why should you "resize" an image to the same size?

Anyway... I understand that the image you have is a jpeg. Opening and resaving a jpeg is almost always losing quality.

You should really use png instead.

Secondly, ppi, dpi or whatever is not important. This is not about quality and it affects neither file size nor screen view quality. It only affects printing size.

If you want to, you can try:
b.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution);


我删除了您发布的答案",因为它实际上只是在重申问题.为此,请编辑您的帖子.


I deleted the ''answer'' you posted because it was really just restating the question. Edit your post for that.


moroshko写道:
moroshko wrote:

我已经注意到,即使图片大小减小了一点,文件大小也大大减小了.我只想了解原因.

I''ve noticed that even if the picture size decreases a little, the file size decreases very much. I just want to understand why.



有人告诉你为什么. JPEG是有损的,因此您的原始JPEG已经不是原始位图的完美副本.应用默认的JPEG压缩级别,甚至会损失更多.如果要保留所有数据,则应以无损格式保存.但是,正如某人已经告诉您的那样,您可以添加一些代码以100%的压缩率保存(这仍然是有损的,但会为您增加文件的大小).




You were told why. JPEG is lossy, and so your original JPEG is already not a perfect copy of hte original bitmap. Applying the default level of JPEG compression, loses even more. You should save in a lossless format if you want to keep all your data. However, as someone already told you, you can add some code to save using a compression of 100% ( which is still lossy, but will make the file bigger for you ).


moroshko写道:
moroshko wrote:

您能建议如何调整JPEG大小,使输出图片具有最高质量吗?

Could you suggest how to resize JPEGs such that the output picture will be with highest quality ?



没有人可以添加到已经给出的答案中.



There is nothing anyone can add to the answers you were already given.


而且,如果您真的必须将其保留为jpeg,请查看 http://en.wikipedia.org/wiki/JPEG#Lossless_editing

因此,您可以旋转,裁剪(或类似操作),但可悲的是,它并没有说明调整大小.
And, if you really have to keep it jpeg, take a look at http://en.wikipedia.org/wiki/JPEG#Lossless_editing

So, you can rotate, crop (and similar), but sadly, it does not say anything about resizing.


这篇关于调整图片大小的基本知识或图片大小发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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