Using .DrawToBitmap - how to change resolution of image?

后端 未结 2 2024
情书的邮戳
情书的邮戳 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);
        }
    
    0 讨论(0)
  • 2021-01-19 18:22

    you can achieve this by increasing the value of second parameter of System.Drawing.Font.

    this.label1.Font = new System.Drawing.Font("Baskerville Old Face", 1000F);
    
    0 讨论(0)
提交回复
热议问题