예제 #1
0
        /// <summary>
        /// Generate a bitmap based on a dot
        /// </summary>
        /// <param name="d"></param>
        /// <param name="idx"></param>
        /// <returns></returns>
        Bitmap DrawCell(Dot d, Brush stripeBrush, int idx = -1)
        {
            int curX = 0;
            int curY = 0;

            Bitmap   res = new Bitmap(Constants.cellW, Constants.cellH);
            Graphics g   = Graphics.FromImage(res);

            Pen p = new Pen(new SolidBrush(Color.Black), 2);

            d.FillCircle();
            int ms = d.MinSize();

            bool[,] dot1Grid = new bool[ms, ms];
            //render dots based on offset settings
            d.RenderToGrid(dot1Grid);

            //Debug.Print(string.Format("Density of {0} is {1}", idx, GetDensity(dot1Grid)));

            Bitmap d1b = ConvertToBMP(dot1Grid);
            //d1b.Save("d1b.bmp");

            //if (idx != -1 && idx < 5)
            //{
            //    WriteOutBMP(idx.ToString() + "b", d1b);
            //    WriteOutGrid(idx.ToString() + "g", dot1Grid);
            //}

            TextureBrush tb1 = new TextureBrush(d1b);
            Rectangle    r   = new Rectangle(curX, curY, Constants.cellW - Constants.padding, Constants.cellH - Constants.padding);

            g.FillRectangle(tb1, r);

            List <Point> pts = new List <Point>()     // coordinates for diagonal stripe, assumes cell w < h
            {
                new Point(curX, curY + Constants.offY + Constants.cellW - Constants.offL),
                new Point(curX, curY + Constants.offY + Constants.cellW),
                new Point(curX + Constants.offL, curY + Constants.offY + Constants.cellW),
                new Point(curX + Constants.cellW - Constants.padding, curY + Constants.offY + Constants.offL),
                new Point(curX + Constants.cellW - Constants.padding, curY + Constants.offY),
                new Point(curX + Constants.cellW - Constants.offL, curY + Constants.offY)
            };

            g.FillPolygon(stripeBrush, pts.ToArray());

            if (d.DrawThick)
            {
                p = new Pen(new SolidBrush(Color.Black), 8);
            }

            g.DrawRectangle(p, r);

            //if (idx != -1)
            //    res.Save(idx.ToString() + ".bmp");
            return(res);
        }
예제 #2
0
        /// <summary>
        /// Render the list of cells to a page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            g.PageUnit = GraphicsUnit.Pixel;

            List <int> lc = Enumerable.Range(0, Constants.NumColumns).ToList();
            List <int> lr = Enumerable.Range(0, Constants.NumRows).ToList();

            Brush stripeBrush = null;

            if (CurrentFG == null)
            {
                CurrentFG = Cartesian.First();
            }

            //Dot fg = GetDot(txtPageNumberFG.Text, txtCellFG.Text, "FG");
            //if (fg == null)
            //{
            //    stripeBrush = new SolidBrush(Color.Gray);
            //}
            //else
            //{
            int ms = CurrentFG.MinSize();

            bool[,] fgGrid = new bool[ms, ms];
            CurrentFG.RenderToGrid(fgGrid);
            Bitmap fgb = ConvertToBMP(fgGrid, false);

            stripeBrush = new TextureBrush(fgb);
            //}

            var results = lr./*AsParallel().*/ Select(
                r => lc./*AsParallel().*/ Select(
                    c => (r * Constants.NumColumns + c >= (useCartesian ? Cartesian.Count() : SubCartesian.Count()) ?
                          new Bitmap(Constants.cellW, Constants.cellH) :
                          DrawCell((useCartesian ? Cartesian.ElementAt(r * Constants.NumColumns + c) :
                                    SubCartesian.ElementAt(r * Constants.NumColumns + c)), stripeBrush, r * Constants.NumColumns + c))).ToList()).ToList();

            var results2 = results./*AsParallel().*/ Select(x => StitchBMPsHoriz(x)).ToList();

            //var results3 = StitchBMPsVert(results2);
            int row = Constants.shiftY;
            int pg  = 0;

            foreach (Bitmap b in results2)
            {
                b.SetResolution(Constants.DPI, Constants.DPI);
                g.DrawImage(b, new Rectangle(Constants.shiftX, row, b.Width, b.Height),
                            new Rectangle(0, 0, b.Width, b.Height), GraphicsUnit.Pixel);
                //g.DrawImageUnscaled(b, 0, row);
                row += b.Height;
                //if (row == 2)
                //    break;
                //WriteOutBMP("out" + pg.ToString(), b);
                pg++;
            }

            //int yy = Constants.shiftY;
            //int rowNum = 1;
            Font       f  = new Font("Arial", 10f, FontStyle.Regular);
            SolidBrush br = new SolidBrush(Color.Black);

            for (int y = 0; y < Constants.NumRows; y++)
            {
                g.DrawString((y + 1).ToString(), f, br, new PointF(0, y * Constants.cellH + Constants.shiftY));
            }

            //int xx = Constants.shiftX;
            char colNum = 'A';

            for (int x = 0; x < Constants.NumColumns; x++)
            {
                g.DrawString(colNum.ToString(), f, br, new PointF(x * Constants.cellW + Constants.shiftX, 0));
                colNum++;
            }
            //while (xx < Constants.PageW)
            //{
            //    g.DrawString(colNum.ToString(), f, br, new PointF(xx, 0));
            //    xx += Constants.cellW;
            //    colNum++;
            //}

            g.DrawString(string.Format("Page {0}, Darkness {1}", Page + 1, Density), f, br, new PointF(50, Constants.PageH - 50));
            e.HasMorePages = false;
        }