C# 和 Photoshop 之间图像分辨率 (ppi) 的差异

发布于 2024-12-21 05:03:46 字数 383 浏览 1 评论 0原文

例如,C# 表示所选图像包含 96 ppi,而 Photoshop 中的同一图像包含 72 ppi。

为什么会有差异?

在这种情况下我倾向于信任 Photoshop,如果 C# 返回错误结果,如何测试图像分辨率?

我们需要构建某种验证器控件,拒绝所有 ppi != 300 的图像

。控件应支持以下格式:jpg、jpeg、gif、png、bmp。

代码如下:

Image i = Image.FromFile(FileName);

Console.Write(i.VerticalResolution);
Console.Write(i.HorizontalResolution);

For example, C # says that the selected image contains 96 ppi, while that same image in Photoshop contains 72 ppi.

Why is there a difference?

I’m inclined to trust Photoshop in this case, and how to test image resolution if C# returns false results?

We need to build some sort of validator control that rejects all images with ppi != 300.

Control should support the following formats: jpg, jpeg, gif, png, bmp.

Code is listed below:

Image i = Image.FromFile(FileName);

Console.Write(i.VerticalResolution);
Console.Write(i.HorizontalResolution);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

☆獨立☆ 2024-12-28 05:03:46

DPI 表示每英寸点数(像素)。以英寸为单位的物理尺寸是主观的,基于当前显示器的尺寸和分辨率。除非您依赖元数据(gif 和 bmp 不包含元数据),否则您无法可靠地计算此值。

Photoshop 只是有一个规定的 DPI 值,它在翻译图像进行打印时使用该值。该值存储在 PSD 文件中,并且可以复制到 JPEG 元数据,但如果以没有 DPI 元数据的格式保存图像,则不会存储该信息。

更新

您的代码获得不同值的原因是 C# 从计算机上当前的 DPI 设置中获取其 VerticalResolutionHorizo​​ntalResolution 值。 Photoshop 的 DPI 用于打印,因此如果您想将图像发送到打印机,它知道物理尺寸。它的默认值为 72dpi,但您可以更改此值。不过,该值在屏幕上没有任何意义,因为屏幕仅处理像素。

DPI means dots (pixels) per inch. The physical size in inches is subjective, based on the current monitor's size and resolution. Unless you're relying on metadata (which gif and bmp don't contain) you cannot reliably calculate this.

Photoshop simply has a prescribed value for DPI, which it uses when translating images for print. This value is stored in the PSD file and may be copied to JPEG metadata, but if you save the image in a format without DPI metadata, the information is not stored.

Update:

The reason your code gets a different value is that C# fetches its VerticalResolution and HorizontalResolution values from the current DPI setting on the computer. Photoshop's DPI is for use with print, so it knows the physical dimensions if you want to send your image to a printer. It has a default value of 72dpi, but you can change this. The value has no meaning on a screen, though, since screens deal in pixels only.

秋风の叶未落 2024-12-28 05:03:46

DPI 表示每英寸点数。位图图像没有固有的 DPI,它只有一个尺寸,即水平方向的像素数和垂直方向的像素数(宽度和高度)。只有当您说出要在每英寸中压缩多少像素时,图像才会获得分辨率(以 DPI 为单位)。

因此,如果我有一个宽 100 像素、高 100 像素 (100px × 100px) 的图像,如果我打印它(或将其转换为指定打印尺寸的格式),则它的 DPI 将为 100,以便它完全适合一平方英寸 (1" × 1")。如果我将其打印到 2 英寸 x 2 英寸的正方形中,则分辨率将为 50 DPI,&c。

DPI means dots per inch. A bitmap image does not have an inherent DPI, it merely has a size which is the number of pixels in the horizontal and the number of pixels in the vertical (width and height). An image only gains a resolution (in DPI) when you say how many pixels you want to squeeze into each inch.

So if I have an image that is 100 pixels wide and 100 pixels high (100px × 100px), it will be 100 DPI if I print it (or convert it into a format that dictates the print size) such that it fits exactly in a one square inch (1" × 1"). It will be 50 DPI if I print it to fit in a square that is two inches by two inches, &c.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文