0

こんにちは、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;
    }
4

1 に答える 1