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;
                }
            }
  • 相关阅读:
    HDU1029 Ignatius and the Princess IV
    UVA11039 Building designing【排序】
    UVA11039 Building designing【排序】
    POJ3278 HDU2717 Catch That Cow
    POJ3278 HDU2717 Catch That Cow
    POJ1338 Ugly Numbers(解法二)
    POJ1338 Ugly Numbers(解法二)
    UVA532 Dungeon Master
    UVA532 Dungeon Master
    POJ1915 Knight Moves
  • 原文地址:https://www.cnblogs.com/kunkka/p/6736885.html
Copyright © 2011-2022 走看看