Using .DrawToBitmap - how to change resolution of image?

后端 未结 2 2027
情书的邮戳
情书的邮戳 2021-01-19 17:50

Im using DrawToBitmap to save some labels as image. I would like to know how to change the resolution of these images, is there a way? Say I have a label with a

2条回答
  •  终归单人心
    2021-01-19 18:20

    Something like this will do the job, just increase font size used from label:

        Bitmap CreateBitmapImage(string text, Font textFont, SolidBrush textBrush)
        {
            Bitmap bitmap = new Bitmap(1, 1);
            Graphics graphics = Graphics.FromImage(bitmap);
            int intWidth = (int)graphics.MeasureString(text, textFont).Width;
            int intHeight = (int)graphics.MeasureString(text, textFont).Height;
            bitmap = new Bitmap(bitmap, new Size(intWidth, intHeight));
            graphics = Graphics.FromImage(bitmap);
            graphics.Clear(Color.White);
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            graphics.DrawString(text, textFont, textBrush,0,0);
            graphics.Flush();
            return (bitmap);
        }
    

提交回复
热议问题