问题描述
我编写了一个程序来调整图片的大小,如下所示:
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 !
推荐答案
b.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution);
我已经注意到,即使图片大小减小了一点,文件大小也大大减小了.我只想了解原因.
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 ).
您能建议如何调整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.
这篇关于调整图片大小的基本知识或图片大小发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!