zoukankan      html  css  js  c++  java
  • 分析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;
                }
            }
  • 相关阅读:
    SQL Server中建立自定义函数
    ArcEngnine中IHookHelper的用法
    ERROR:Tried to register widget id ==basemapGalleryDiv but that id is already registered解决办法
    使用dojo.connect()添加事件的注意事项
    ArcGIS Engine环境下创建自定义的ArcToolbox Geoprocessing工具
    已知两点经纬度求航向
    Parallel并行循环
    qt常用技巧
    下载
    arcgis将图片转成shp地图
  • 原文地址:https://www.cnblogs.com/kunkka/p/6736885.html
Copyright © 2011-2022 走看看