• 分析InkCanvas保存的图片是否为全部白色


    1. 从InkCanvas保存图片到Pictures下面

    2. 读取保存的图片分析每个像素是否全为白色

    (由于擦除的痕迹为白色,可能会有不是FFFFFF的痕迹存在,故RGB均大于200以上的点视为白色)

    public async Task<bool> CheckIfSignatureAllWhiteEx(InkStrokeContainer container)
            {
                bool isPixWhite = true;
                try
                {
                    int originalPixelWidth = (int)inkCanvas.ActualWidth;
                    int originalPixelHeight = (int)inkCanvas.ActualHeight;
                    StorageFolder storageFolder = KnownFolders.PicturesLibrary;
                    StorageFile imageFile = await storageFolder.CreateFileAsync("test1.png",
                            CreationCollisionOption.ReplaceExisting);
                    using (IRandomAccessStream stream = await imageFile.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await container.SaveAsync(stream);
                    }
    
                    IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read);
                    WriteableBitmap bitmap = new WriteableBitmap(originalPixelWidth, originalPixelHeight);
                    await bitmap.SetSourceAsync(fileStream);
    
                    Color col = new Color();
                    DataReader DR = DataReader.FromBuffer(bitmap.PixelBuffer);
                    byte[] bytes = new byte[bitmap.PixelBuffer.Capacity];
                    DR.ReadBytes(bytes);
    
                    for (int x = 0; x < bitmap.PixelWidth; x++)
                    {
                        for (int y = 0; y < bitmap.PixelHeight; y++)
                        {
                            col.B = bytes[(y * bitmap.PixelWidth + x) * 4];
                            col.G = bytes[(y * bitmap.PixelWidth + x) * 4 + 1];
                            col.R = bytes[(y * bitmap.PixelWidth + x) * 4 + 2];
                            col.A = bytes[(y * bitmap.PixelWidth + x) * 4 + 3];
    
                            if(col.A!=0 && (col.R<200 || col.G < 200 || col.B < 200))
                            {
                                isPixWhite = false;
                                return isPixWhite;
                            }
                        }
                    }
    
                    return isPixWhite;
                }
                catch (Exception e)
                {
                    
                    return false;
                }
            }
  • 相关阅读:
    Ubuntu 20.04下EasyConnect兼容性问题临时解决方案
    Ubuntu 20.04 LTS安装搜狗输入法,只需三条命令,还能自动更新
    Java笔记: 继承成员覆盖和隐藏
    Java扫雷游戏: JMine
    Emacs: 设置窗口标题格式
    Java笔记: protected的真正含义
    Java笔记: 初始化块
    Ubuntu跨版本安装软件
    百度编辑器 Ueditor 增加字体
    AspCms 升级百度编辑器
  • 原文地址:https://www.cnblogs.com/kunkka/p/6736885.html
Copyright © 2020-2023  润新知