如何使用C#在程序中检查图像质量? [英] How can I check out the picture quality in program using c#?

查看:207
本文介绍了如何使用C#在程序中检查图像质量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

我认为可以确定地检查打印质量的唯一因素(因为其他因素是主观的)是图像的分辨率与预期的打印尺寸.如果您还有其他具体要求,例如图像必须是彩色的,而不是黑白的,则也可以进行检查.但是,尝试确定图像是否太模糊,对比度太低等,将是徒劳的,因为您永远不知道图像是否打算那样做.

一个普遍的经验法则是:打印时每英寸至少应有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 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?

解决方案

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();
        }
    }
}

这篇关于如何使用C#在程序中检查图像质量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆