使用 C# 和 .NET 环境获取 jpeg 图像的分辨率?

发布于 2024-07-05 19:13:08 字数 142 浏览 4 评论 0原文

我们的客户将上传要打印在其文档上的图像,我们被要求想出一种方法来获取图像的分辨率,以便在图像分辨率太低并且在图像中看起来像素化时向他们发出警告最终产品

如果涉及到它,我们也可以选择尺寸,如果有人知道如何获得这些尺寸,但分辨率将是首选

谢谢

Our clients will be uploading images to be printed on their documents and we have been asked to come up with a way to get the resolution of the image in order to warn them if the image has too low of a resolution and will look pixalated in the end-product

If it comes to it we could also go with the dimensions if anyone knows how to get those but the resolution would be preferred

Thank you

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

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

发布评论

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

评论(4

蓝梦月影 2024-07-12 19:13:08

这取决于您要寻找的内容...如果您想要图像的 DPI,那么您正在寻找 Horizo​​ntalResolution,它是图像的 DPI。

Image i = Image.FromFile(@"fileName.jpg");
i.HorizontalResolution;

如果您想计算出图像有多大,那么您需要计算图像的尺寸,即:

int docHeight = (i.Height / i.VerticalResolution);
int docWidth = (i.Width / i.HorizontalResolution);

这将为您提供以英寸为单位的文档高度和宽度,然后您可以将其与所需的最小尺寸进行比较。

It depends what you are looking for... if you want the DPI of the image then you are looking for the HorizontalResolution which is the DPI of the image.

Image i = Image.FromFile(@"fileName.jpg");
i.HorizontalResolution;

If you want to figure out how large the image is then you need to calculate the measurements of the image which is:

int docHeight = (i.Height / i.VerticalResolution);
int docWidth = (i.Width / i.HorizontalResolution);

This will give you the document height and width in inches which you could then compare to the min size needed.

起风了 2024-07-12 19:13:08

System.Drawing.Image

Image newImage = Image.FromFile("SampImag.jpg");
newImage.HorizontalResolution

System.Drawing.Image

Image newImage = Image.FromFile("SampImag.jpg");
newImage.HorizontalResolution
八巷 2024-07-12 19:13:08
Image image = Image.FromFile( [file] );
GraphicsUnit unit = GraphicsUnit.Point;
RectangleF rect = image.GetBounds( ref unit );
float hres = image.HorizontalResolution;
float vres = image.VerticalResolution;
Image image = Image.FromFile( [file] );
GraphicsUnit unit = GraphicsUnit.Point;
RectangleF rect = image.GetBounds( ref unit );
float hres = image.HorizontalResolution;
float vres = image.VerticalResolution;
娇纵 2024-07-12 19:13:08

DPI 仅在打印时才有意义。 72dpi 是 Mac 标准,96dpi 是 Windows 标准。 屏幕分辨率仅考虑像素,因此 72dpi 800x600 jpeg 与 96dpi 800x600 像素的屏幕分辨率相同。

回到 80 年代,Mac 使用 72dpi 屏幕/打印分辨率来适应屏幕/打印尺寸,因此当屏幕上的图像比例为 1:1 时,它对应于打印机上的相同尺寸。 Windows 将屏幕分辨率提高到 96dpi,以获得更好的字体显示。但结果是,屏幕图像不再适合打印尺寸。

因此,对于 Web 项目,如果图像不是用于打印,则不必考虑 DPI; 72dpi,96dpi,甚至1200dpi应该显示相同。

DPI take sense when printing only. 72dpi is the Mac standard and 96dpi is the Windows standard. Screen resolution only takes pixels into account, so a 72dpi 800x600 jpeg is the same screen resolution than a 96dpi 800x600 pixels.

Back to the '80s, Mac used 72dpi screen/print resolution to fit the screen/print size, so when you had an image on screen at 1:1, it correspond to the same size on the printer. Windows increased the screen resolution to 96dpi to have better font display.. but as a consequence, the screen image doesn't fit the printed size anymore.

So, for web project, don't bother with DPI if the image isn't for print; 72dpi, 96dpi, even 1200dpi should display the same.

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