簡體   English   中英

在圖片框上繪制並打印

[英]Draw on picture box and print it

嗨,我想將我的圖片框做成圓形,然后打印出來。

問題是我可以以圖片框的形式看到圓形,但是預覽打印時它不是圓形。

這是我的代碼

 public Form1()
    {
        InitializeComponent();


        //This makes picturebox1 circle
        System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
        gp.AddEllipse(0, 0, pictureBox1.Width - 4, pictureBox1.Height - 4);
        Region rg = new Region(gp);
        pictureBox1.Region = rg;
    }


    //Preview the print
    private void button1_Click(object sender, EventArgs e)
    {
        printPrev.Document = printDoc;
        printPrev.ShowDialog();

    }

    private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {

        //Draw the picturebox on PDF
        e.Graphics.DrawImage(pictureBox1.Image, 230, 230);

    }

謝謝

它不起作用,因為您沒有更改圖像。 您僅在更改圖形。 你可以做這樣的事情。

            Bitmap bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(bitmap);
            g.DrawEllipse(new Pen(new SolidBrush(Color.Black),3),0,0,bitmap.Width -4,bitmap.Height - 4);
            pictureBox1.Image = bitmap;

這也可以解決您的問題

    using (var bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height)) {
                pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0,  bmp.Width,bmp.Height));
                e.Graphics.DrawImage(bmp, 230, 230);
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM