How to save drew Graphics of “Paint()” into image using c#?

前端 未结 2 1231
深忆病人
深忆病人 2021-01-16 22:26

I actually wanted to Convert RTF into Image so after googling a lot I\'ve got a code that does it by Paint() Event of Picturebox1 and it works perfectly : <

2条回答
  •  执念已碎
    2021-01-16 22:39

    Your code produces an empty image file because you are not drawing anything onto 'newBitmap'.

    If you want to draw anything onto 'newBitmap' you need to create a Graphics object from it. As I do not know where 'DrawRtfText' comes from and how it works my guess would be:

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
            //... 
            Bitmap newBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(newBitmap);
            g.DrawRtfText(this.richTextBox1.Rtf, this.pictureBox1.ClientRectangle);
            newBitmap.Save(@"d:\adv.jpg");
    }
    

提交回复
热议问题