设置与高度/宽度相关的图像 DPI C#

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/921003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:14:07  来源:igfitidea点击:

Setting image DPI in relation to height/width C#

c#image

提问by Aaron

I'm writing an application to send some images to a third party, and the images must be 200x200 DPI. The image is a Bitmap and is sized at 500 width and 250 height.

我正在编写一个应用程序来向第三方发送一些图像,图像必须是 200x200 DPI。图像是位图,大小为 500 宽和 250 高。

The first time I tested the images with the third party, my resolution was incorrect. I merely used image.SetResolution(200,200)to correctly set it to 200x200. This, however, only changed the resolution tag for the image and did not properly, according to my third party technical contact, adjust the image height and width.

我第一次用第三方测试图像时,我的分辨率不正确。我只是用来image.SetResolution(200,200)正确地将其设置为 200x200。但是,根据我的第三方技术联系人的说法,这仅更改了图像的分辨率标签,并没有正确调整图像的高度和宽度。

Is there a ratio that I can use so that for each X units I increment the resolution, I merely increment the corresponding height or width Y units? I thought that I could just increment resolution without having to increment height or width.

是否有我可以使用的比率,以便为每个 X 单位增加分辨率,我只增加相应的高度或宽度 Y 单位?我认为我可以只增加分辨率而不必增加高度或宽度。

Thank you, Aaron.

谢谢你,亚伦。

采纳答案by Dana Holt

An image stored digitally has no meaningful concept of DPI. DPI comes into play when reproducing an image on a physical device.

以数字方式存储的图像没有有意义的 DPI 概念。DPI 在物理设备上再现图像时发挥作用。

You need to adjust the image size with regard to the DPI of the physical device, and the desired size of the output on that device.

您需要根据物理设备的 DPI 以及该设备上所需的输出大小调整图像大小。

For example, if a printer tells you they need an image at 300dpi to fill a space of 4in x 4in then you would provide them a bitmap with a size of 1200x1200 pixels. This image would end up with a physical size of 4in x 4in on a 300dpi output device. On a 600dpi device the same image would have an output size of 2in x 2in.

例如,如果打印机告诉您他们需要 300dpi 的图像来填充 4in x 4in 的空间,那么您将为他们提供一个大小为 1200x1200 像素的位图。该图像在 300dpi 输出设备上的物理尺寸为 4in x 4in。在 600dpi 设备上,相同图像的输出尺寸为 2in x 2in。

回答by jgallant

When dealing with digital images, you usually refer to PPI, which is pixels per inch. DPI is not directly related to digital image resolution.

在处理数字图像时,您通常会参考 PPI,即每英寸像素数。DPI 与数字图像分辨率没有直接关系。

So, if you look at a image that is 200px by 200px @ 200PPI, you will have an image that is 1 inch by 1 inch.

因此,如果您查看 200 像素 x 200 像素 @ 200PPI 的图像,您将看到 1 英寸 x 1 英寸的图像。