嗨我想让我的照片框变成圆形 然后打印出来。
问题是我可以在表格中看到图片框是圆圈,但是当我预览它以便打印时它不会圈。
这是我的代码
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);
}
由于
答案 0 :(得分:1)
它不起作用,因为您没有更改图像。 您只是在更改图形。 你可以这样做。
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);
}