简体   繁体   English

我怎么知道我的字节数组包含空白.tif文件

[英]how do i know my byte array containing blank .tif file or not

i have a application where i need to check my scanner generates blank tif file or not. 我有一个需要检查我的扫描仪的应用程序是否生成空白tif文件。 here i share my example code 在这里我分享我的示例代码

 private void button1_Click(object sender, EventArgs e)
    {
        string path2 = @"F:\3333.tif";
        string path = @"F:\Document Scanned @ 1-blank.tif";
        System.Drawing.Image img = System.Drawing.Image.FromFile(path);
        byte[] bytes;
        using (MemoryStream ms = new MemoryStream())
        {
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
            bytes = ms.ToArray();
        }

        System.Drawing.Image img2 = System.Drawing.Image.FromFile(path2);
        byte[] bytes2;

        using (MemoryStream ms3 = new MemoryStream())
        {
            img2.Save(ms3, System.Drawing.Imaging.ImageFormat.Tiff);
            bytes2 = ms3.ToArray();
        }
        bool t = false;
        t = bytes.SequenceEqual(bytes2);
    }

Note: Blank tif image meance white page . 注意:空白tif图像仅出现白页。

In above bool t always returns true why ? 在上面的布尔总是返回true为什么? i used two diff images solved 我用两个差异图像解决了

Essentially, you are comparing the bytes of two TIF files (with the indirection of using Image ). 本质上,您正在比较两个TIF文件的字节(与使用Image的间接作用)。 This can fail for various reasons: 这可能由于各种原因而失败:

Dimension : If the two images do not have the exact same height and width, the byte sequences will -of course- be different even if both are completely white. 尺寸 :如果两个图像的高度和宽度不完全相同,则字节序列当然也会有所不同,即使它们都是完全白色的。

Metadata : As far as I know, the TIF format contains various metadata. 元数据 :据我所知,TIF格式包含各种元数据。 Therefore, two files may be different even if they have the same pixels. 因此,即使两个文件具有相同的像素,它们也可能不同。 I would recommend manually checking all pixel values (eg Bitmap.GetPixel ) and comparing them to white ( Color.FromArgb(255,255,255,255) ). 我建议手动检查所有像素值(例如Bitmap.GetPixel )并将它们与白色进行比较( Color.FromArgb(255,255,255,255) )。

Noise : Are you sure that a blank file is always pure white (255,255,255) ? 噪音 :您确定空白文件始终是纯白色(255,255,255)吗? Maybe some random pixels have slightly different values such as (255,254,255) ... 也许某些随机像素的值略有不同,例如(255,254,255) ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM