Neos.IdentityServer 3.0/Neos.IdentityServer.QrCodeNet/Windows/Render/WriteableBitmapRenderer.cs
/// <summary>
/// Draw qrCode dark modules at given position. (It will also include quiet zone area. Set it to zero to exclude quiet zone)
/// </summary>
/// <exception cref="ArgumentNullException">Bitmatrix, wBitmap should not equal to null</exception>
/// <exception cref="ArgumentOutOfRangeException">wBitmap's pixel width or height should not equal to zero</exception>
Draw qrCode dark modules at given position. (It will also include quiet zone area. Set it to zero to exclude quiet zone)
Draw qrCode dark modules at given position . ( It will also include quiet zone area . Set it to zero to exclude quiet zone )
public void DrawDarkModule(WriteableBitmap wBitmap, BitMatrix matrix, int offsetX, int offsetY)
        {
            if (matrix == null)
                throw new ArgumentNullException("Bitmatrix");
            DrawingSize size = ISize.GetSize(matrix.Width);
            if (wBitmap == null)
                throw new ArgumentNullException("wBitmap");
            else if (wBitmap.PixelHeight == 0 || wBitmap.PixelWidth == 0)
                throw new ArgumentOutOfRangeException("wBitmap", "WriteableBitmap's pixelHeight or PixelWidth are equal to zero");
            int padding = (size.CodeWidth - size.ModuleSize * matrix.Width) / 2;
            int preX = -1;
            int moduleSize = size.ModuleSize;
            if (moduleSize == 0)
                return;
            for (int y = 0; y < matrix.Width; y++)
            {
                for (int x = 0; x < matrix.Width; x++)
                {
                    if (matrix[x, y])
                    {
                        if (preX == -1)
                            preX = x;
                        if (x == matrix.Width - 1)
                        {
                            Int32Rect moduleArea =
                                new Int32Rect(preX * moduleSize + padding + offsetX,
                                    y * moduleSize + padding + offsetY,
                                    (x - preX + 1) * moduleSize,
                                    moduleSize);
                            wBitmap.FillRectangle(moduleArea, DarkColor);
                            preX = -1;
                        }
                    }
                    else if (preX != -1)
                    {
                        Int32Rect moduleArea =
                            new Int32Rect(preX * moduleSize + padding + offsetX,
                                y * moduleSize + padding + offsetY,
                                (x - preX) * moduleSize,
                                moduleSize);
                        wBitmap.FillRectangle(moduleArea, DarkColor);
                        preX = -1;
                    }
                }
            }
        }
public void DrawDarkModule ( WriteableBitmap wBitmap , BitMatrix matrix , int offsetX , int offsetY ) { if ( matrix == null ) throw new ArgumentNullException ( " " ) ; DrawingSize size = ISize . GetSize ( matrix . Width ) ; if ( wBitmap == null ) throw new ArgumentNullException ( " " ) ; else if ( wBitmap . PixelHeight == 0 || wBitmap . PixelWidth == 0 ) throw new ArgumentOutOfRangeException ( " " , " " ) ; int padding = ( size . CodeWidth - size . ModuleSize * matrix . Width ) / 2 ; int preX = - 1 ; int moduleSize = size . ModuleSize ; if ( moduleSize == 0 ) return ; for ( int y = 0 ; y < matrix . Width ; y ++ ) { for ( int x = 0 ; x < matrix . Width ; x ++ ) { if ( matrix [ x , y ] ) { if ( preX == - 1 ) preX = x ; if ( x == matrix . Width - 1 ) { Int32Rect moduleArea = new Int32Rect ( preX * moduleSize + padding + offsetX , y * moduleSize + padding + offsetY , ( x - preX + 1 ) * moduleSize , moduleSize ) ; wBitmap . FillRectangle ( moduleArea , DarkColor ) ; preX = - 1 ; } } else if ( preX != - 1 ) { Int32Rect moduleArea = new Int32Rect ( preX * moduleSize + padding + offsetX , y * moduleSize + padding + offsetY , ( x - preX ) * moduleSize , moduleSize ) ; wBitmap . FillRectangle ( moduleArea , DarkColor ) ; preX = - 1 ; } } } }
Draw qrCode dark modules at given position.
Draw qrCode dark modules at given position .
Bitmatrix, wBitmap should not equal to null
Bitmatrix wBitmap should not equal to null
wBitmap's pixel width or height should not equal to zero
wBitmap ' s pixel width or height should not equal to zero
wBitmap
WriteableBitmap
matrix
BitMatrix
offsetX
int
offsetY
int