嗨,我想在 c# 中的图像上绘制一些信息。我写了这段代码,它可以工作:
Bitmap bmp = new Bitmap(@"G:\Cert_template.png");
Graphics g = Graphics.FromImage(bmp);
g.DrawString(cert_id, new Font("B Zar", 3,System.Drawing.FontStyle.Bold), Brushes.Black, new Point(85, 95));
g.DrawString(date_cert, new Font("B Zar", 3, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(85, 135));
g.DrawString(s1 + s3, new Font("B Zar", 4, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(90, 290));
g.DrawString(s4, new Font("B Zar", 3, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(480, 360));
g.DrawString(date_exam, new Font("B Zar", 3, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(170, 515));
g.DrawString(Convert.ToString(mark), new Font("B Zar", 3, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(520, 600));
g.DrawString(lvl, new Font("B Zar", 3, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(150, 600));
g.DrawString(prvnc, new Font("B Zar", 3, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(170, 780));
g.DrawString(center, new Font("B Zar", 3, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(310, 870));
g.DrawString(inst, new Font("B Zar", 3, System.Drawing.FontStyle.Bold), Brushes.Black, new Point(150, 870));
CaptureScreen(g,imgCounter);
对于我写的所有信息,我的形象都是一样的。我把这段代码放在一个循环中,它会绘制图像,但对于不同的信息,它会覆盖以前的图像。我想清除图像并再次在其上书写而不覆盖。
编辑
之后,我发送g
到一个函数以显示在图片框中:
private void CaptureScreen(Graphics g,int imgCounter)
{
/*This method captures a snapshot of screen and
* adds it to the ImageFlowLayoutPanel
*/
bmp.Save("snap" + imgCounter.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
//creating a picturebox control and add it to the flowlayoutpanel
PictureBox tempPictureBox = new PictureBox();
//generates a thumbnail image of specified size
tempPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
tempPictureBox.Image = bmp.GetThumbnailImage(600, 700,
new Image.GetThumbnailImageAbort(ThumbnailCallback),
IntPtr.Zero);
tempPictureBox.Size = new System.Drawing.Size(50,50);
tempPictureBox.Click += new EventHandler(this.tempPictureBox_Click);
ImageFlowLayoutPanel.Controls.Add(tempPictureBox);
}
//This click event will be used to display the enlarged images
private void tempPictureBox_Click(object sender, EventArgs e)
{
PreviewPictureBox.Image = ((PictureBox)sender).Image;
}
public bool ThumbnailCallback()
{
return true;
}