c# drawing text using custom pixels

孤街浪徒 提交于 2019-11-28 14:41:59

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!