如何使用c#检查程序中的图像质量?

发布于 2024-08-27 05:45:05 字数 58 浏览 10 评论 0原文

我想使用我的应用程序检查照片是否适合打印。我该怎么做?我对照片质量不太了解?每张照片的分辨率是否相同?

I want to check out whether the photograph is suitable for print or not using my application.How can I do that?I don't know much about photo quality?Is the resolution of every photograph is same or not?

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

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

发布评论

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

评论(2

携君以终年 2024-09-03 05:45:05

我认为您可以确定地检查打印质量的唯一因素(因为其他因素是主观的)是图像的分辨率与预期的打印尺寸。如果您有其他具体要求,例如图像必须是彩色的,而不是黑白的,您也可以检查一下。但试图识别图像是否太模糊、对比度太低等,很可能是徒劳的,因为你永远不知道图像是否是有意为之。

一个常见的经验法则是,打印时每英寸至少应有 240 个点,300 个点更好。当然,对于高质量打印机,更高的分辨率可以产生更好的结果,如果您要打印非常高的细节,例如精细文本,您可能需要达到 600dpi 及以上。

因此,要使用最小 240 dpi 的数字打印 8" x 10" 图像,您需要的图像至少为 1920 x 2400 像素(总共 4,608,000 像素,或约 4.5 兆像素)。

如果您决定打印 8" x 10" 时至少需要 300dpi,那么您需要至少 2400 x 3000 像素的图像,即大约 7 兆像素。

提高到 600dpi?在这种情况下,您需要大约 28 兆像素的图像。

示例:

using System;
using System.Drawing;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int minimumPrintDpi = 240;
            int targetPrintWidthInches = 8;
            int targetPrintHeightInches = 10;
            int minimumImageWidth = targetPrintWidthInches * minimumPrintDpi;
            int minimumImageHeight = targetPrintHeightInches * minimumPrintDpi;

            var img = Image.FromFile(@"C:\temp\CaptainKangaroo.jpg");

            Console.WriteLine(string.Format("Minimum DPI for printing: {0}", minimumPrintDpi));
            Console.WriteLine(string.Format("Target print size: width:{0}\" x height:{1}\"", targetPrintWidthInches, targetPrintHeightInches));
            Console.WriteLine(string.Format("Minimum image horizontal resolution: {0}", minimumImageWidth));
            Console.WriteLine(string.Format("Minimum image vertical resolution: {0}", minimumImageHeight));
            Console.WriteLine(string.Format("Actual Image horizontal resolution: {0}", img.Width));
            Console.WriteLine(string.Format("Actual Image vertical resolution: {0}", img.Height));
            Console.WriteLine(string.Format("Actual image size in megapixels: {0}", ((float)img.Height * img.Width) / 1000000));
            Console.WriteLine(string.Format("Image resolution sufficient? {0}", img.Width >= minimumImageWidth && img.Height >= minimumImageHeight));
            Console.WriteLine(string.Format("Maximum recommended print size for this image: width:{0}\" x height:{1}\"", (float)img.Width / minimumPrintDpi, (float)img.Height / minimumPrintDpi));

            Console.ReadKey();
        }
    }
}

I think the only factor in print quality that you can check with any certainty (because the other factors are subjective), is the resolution of the image vs. the intended print size. If you have other tangible requirements, like the image must be color, not black and white, you can check for that too. But trying to identify whether an image is too blurry, low contrast, etc., will likely be a fruitless pursuit, as you never know whether the image was intended to be that way or not.

A common rule of thumb is that you should have at least 240 dots per inch when printing, and 300 is even better. Of course with quality printers, higher resolution than that can yield better results, and if you are printing very high detail, like fine text, you may want to go to 600dpi and above.

So to print an 8" x 10" image using the minimum figure of 240 dpi, you would want an image that is at least 1920 x 2400 pixels (a total of 4,608,000 pixels, or about 4.5 megapixels).

If you decide you want at least 300dpi when printing an 8" x 10", then you want an image with at least 2400 x 3000 pixels, which is about 7 megapixels.

Stepping up to 600dpi? You'll need about a 28 megapixel image in that case.

Example:

using System;
using System.Drawing;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int minimumPrintDpi = 240;
            int targetPrintWidthInches = 8;
            int targetPrintHeightInches = 10;
            int minimumImageWidth = targetPrintWidthInches * minimumPrintDpi;
            int minimumImageHeight = targetPrintHeightInches * minimumPrintDpi;

            var img = Image.FromFile(@"C:\temp\CaptainKangaroo.jpg");

            Console.WriteLine(string.Format("Minimum DPI for printing: {0}", minimumPrintDpi));
            Console.WriteLine(string.Format("Target print size: width:{0}\" x height:{1}\"", targetPrintWidthInches, targetPrintHeightInches));
            Console.WriteLine(string.Format("Minimum image horizontal resolution: {0}", minimumImageWidth));
            Console.WriteLine(string.Format("Minimum image vertical resolution: {0}", minimumImageHeight));
            Console.WriteLine(string.Format("Actual Image horizontal resolution: {0}", img.Width));
            Console.WriteLine(string.Format("Actual Image vertical resolution: {0}", img.Height));
            Console.WriteLine(string.Format("Actual image size in megapixels: {0}", ((float)img.Height * img.Width) / 1000000));
            Console.WriteLine(string.Format("Image resolution sufficient? {0}", img.Width >= minimumImageWidth && img.Height >= minimumImageHeight));
            Console.WriteLine(string.Format("Maximum recommended print size for this image: width:{0}\" x height:{1}\"", (float)img.Width / minimumPrintDpi, (float)img.Height / minimumPrintDpi));

            Console.ReadKey();
        }
    }
}
窗影残 2024-09-03 05:45:05

有很多因素可以区分图像的“质量好”和“质量差”

维基百科有一个简短的这些因素列表

其中大多数都很难以编程方式检查,并且涉及复杂的成像算法。然而,如果分辨率是好坏图像之间的唯一标准,那么检查分辨率很容易。

这个简单的代码告诉你如何做到这一点

我认为获得解决方案的最基本代码是这样的

  Bitmap bmp = new Bitmap("winter.jpg");

  Console.WriteLine("Image resolution: " + bmp.HorizontalResolution + " DPI");
  Console.WriteLine("Image resolution: " + bmp.VerticalResolution + " DPI");
  Console.WriteLine("Image Width: " + bmp.Width);
  Console.WriteLine("Image Height: " + bmp.Height);

There are a great many factors that will differentiate an image that is "of good quality" and "of bad quality"

wikipedia has a short list of those factors

Most of these are rather hard to check for programatically and involve complex imaging algorithms. Checking for resolution is easy however, if it is the only criteria between a good and a bad image.

This simple code tells you how to do it

I think the most basic code to get resolution is this

  Bitmap bmp = new Bitmap("winter.jpg");

  Console.WriteLine("Image resolution: " + bmp.HorizontalResolution + " DPI");
  Console.WriteLine("Image resolution: " + bmp.VerticalResolution + " DPI");
  Console.WriteLine("Image Width: " + bmp.Width);
  Console.WriteLine("Image Height: " + bmp.Height);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文