Example #1
0
        protected static IntPtr GetHalfToneBrush()
        {
            if (_halfToneBrush == IntPtr.Zero)
            {
                Bitmap bitmap = new Bitmap(8, 8, PixelFormat.Format32bppArgb);

                Color white = Color.FromArgb(255, 255, 255, 255);
                Color black = Color.FromArgb(255, 0, 0, 0);

                bool flag = true;

                // Alternate black and white pixels across all lines
                for (int x = 0; x < 8; x++, flag = !flag)
                {
                    for (int y = 0; y < 8; y++, flag = !flag)
                    {
                        bitmap.SetPixel(x, y, (flag ? white : black));
                    }
                }

                IntPtr hBitmap = bitmap.GetHbitmap();

                Win32.LOGBRUSH brush = new Win32.LOGBRUSH();

                brush.lbStyle = (uint)Win32.BrushStyles.BS_PATTERN;
                brush.lbHatch = (uint)hBitmap;

                _halfToneBrush = Gdi32.CreateBrushIndirect(ref brush);
            }

            return(_halfToneBrush);
        }
Example #2
0
        protected static IntPtr GetHalfToneBrush()
        {
            if (_halfToneBrush == IntPtr.Zero)
            {
                Bitmap bitmap = new Bitmap(8,8,PixelFormat.Format32bppArgb);

                Color white = Color.FromArgb(255,255,255,255);
                Color black = Color.FromArgb(255,0,0,0);

                bool flag=true;

                // Alternate black and white pixels across all lines
                for(int x=0; x<8; x++, flag = !flag)
                    for(int y=0; y<8; y++, flag = !flag)
                        bitmap.SetPixel(x, y, (flag ? white : black));

                IntPtr hBitmap = bitmap.GetHbitmap();

                Win32.LOGBRUSH brush = new Win32.LOGBRUSH();

                brush.lbStyle = (uint)Win32.BrushStyles.BS_PATTERN;
                brush.lbHatch = (uint)hBitmap;

                _halfToneBrush = Gdi32.CreateBrushIndirect(ref brush);
            }

            return _halfToneBrush;
        }