c# drawing text using custom pixels

前端 未结 1 1740
刺人心
刺人心 2020-12-12 07:58

I\'m wondering if that\'s possible: I got a c# application with something like a display consisting of about 11000 circles drawn on the Form.

What I want to achieve

1条回答
  •  死守一世寂寞
    2020-12-12 08:17

    You could write on an invisible BitMap with the DrawText method and then scan the bitmap's pixels and turn the corresponding circles on.

    Did that last week with the cells of DataGridView. Real easy.

    Here is some code:

        public void drawText(string text, Font drawFont)
        {
            Bitmap bmp = new Bitmap(canvasWidth, canvasHeight);
            Graphics G = Graphics.FromImage(bmp);
            SolidBrush brush = new SolidBrush(paintColor);
            Point point = new Point( yourOriginX, yourOriginY );
    
            G.DrawString(text, drawFont, brush, point);
    
            for (int x = 0; x < canvasWidth; x++)
                for (int y = 0; y < canvasHeight; y++)
                {
                    Color pix = bmp.GetPixel(x, y);
                        setCell(x, y, pix);     //< -- set your custom pixels here!
                }
            bmp.Dispose();
            brush.Dispose();
            G.Dispose();
        }
    

    Edit: You would use your dimensions and your origin for the DrawString, of course

    0 讨论(0)
提交回复
热议问题