Example #1
0
        private static void CreateMillimiterGridBrush(Dpi dpi)
        {
            SizeF sizeMM = new SizeF(500.0f, 250.0f);
            Size sizePx = new Size(dpi.GetPxFromMM_X(sizeMM.Width), dpi.GetPxFromMM_Y(sizeMM.Height));

            // 30.07.2011 (FK) PixelFormat.Format32bppPArgb by mel byt nejoptimalnejsi format bitmapy pro GDI+
            _millimeterGridBitmap = new Bitmap(sizePx.Width, sizePx.Height, PixelFormat.Format32bppPArgb);
            _millimeterGridBitmap.SetResolution(dpi.DpiX, dpi.DpiY);

            using (Graphics bg = Graphics.FromImage(_millimeterGridBitmap))
            {
                RectangleF gridRectMM = new RectangleF(PointF.Empty, sizeMM);

                bg.Clear(_gridBackgroundColor);

                bg.PageUnit = GraphicsUnit.Millimeter;
                bg.SmoothingMode = SmoothingMode.HighQuality;

                Pen gridPen1 = new Pen(Color.FromArgb(20, _gridColor), 0.0f);
                DrawGrid(bg, gridPen1, gridRectMM, 1.0f);

                bg.SmoothingMode = SmoothingMode.None;

                Pen gridPen5 = new Pen(Color.FromArgb(30, _gridColor), 0.0f);
                DrawGrid(bg, gridPen5, gridRectMM, 5.0f);

                Pen gridPen10 = new Pen(Color.FromArgb(40, _gridColor), 0.0f);
                DrawGrid(bg, gridPen10, gridRectMM, 10.0f);
            }

            // 30.07.2011 (FK) Texture brush je asi nejrychlejsi moznost jak kreslit vetsi plochy stejnou bitmapou v GDI+
            // viz http://stackoverflow.com/questions/264720/gdi-graphicsdrawimage-really-slow
            _millimeterGridBrush = new TextureBrush(_millimeterGridBitmap, WrapMode.Tile);
        }