如何在 C#.Net 中裁剪图像而不更改其分辨率?
我制作了一个小程序来分割大图片并截取其中的一部分。 当我导入由“Microsoft Paint”制作的图像时,该图像是“96 dpi”,所以我的程序运行良好。
但我有一些由 Photoshop 制作的图片,其分辨率为 71.6 dpi,当我裁剪这些图片时,新裁剪的图片采用 96 dpi 分辨率,因此尺寸是它们之间的差异。
我想裁剪图片并保持其分辨率不变。
.
非常感谢
I made small program to divide large pictures and take part of them.
When i import image that made by "Microsoft Paint" this image is "96 dpi" so my program doing well.
But I've pictures that made by Photoshop its resolution is 71.6 dpi when i crop these pictures the new cropped picture take 96 dpi resolution so the size is deference between them.
I want to crop the picture with keeping its resolution as it.
.
thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Bitmap.clone
允许您创建图像的裁剪副本,然后可以保存该副本。 它不应该改变分辨率或任何东西(如果您在图像较小时放大更多的程序中打开图像,图像看起来会更大)。 它不能用于扩展画布(您会遇到内存不足错误)。 因此,只需从文件中获取Image
,转换为Bitmap
(system.drawing
命名空间)并将其克隆为更小,然后保存。例子:
Bitmap.clone
lets you create a cropped copy of an image, which you can then save. It shouldn't change resolution or anything (the image will look bigger if you open it in a program that zooms in more when images are smaller). It cannot be used to expand the canvas (you'll get out of memory errors). So, just grab anImage
from file, cast toBitmap
, (system.drawing
namespace) and clone it to be smaller, then save it.Example:
DPI(每英寸点数)只是像素大小与介质大小之间的关系。 如果您有一个 1024 x 768 像素的图像,那么它就是 1024 x 768。位图/二进制文件没有附加固有的 DPI。
例如,如果您想在以 300 dpi 打印的打印机上打印该图像,则可以计算纸张上的尺寸。
DPI (dots per inch) is just a relationship between pixel size and the size on a medium. If you have an image which is 1024 x 768 pixels, it is 1024 x 768. There is no inherent DPI attached to a bitmap/binary file.
If you want to print that image on a printer which prints at 300 dpi, then you can calculate the size on the paper, for example.
Bitmap 类的 SetResolution() 方法允许您指定图像的分辨率。
请参阅 http://msdn.microsoft.com/en -us/library/system.drawing.bitmap.setresolution.aspx
The SetResolution() method of the Bitmap class allows you to specify the resolution of an image.
See http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.setresolution.aspx