我需要保存picturebox加载的png文件与picturebox背景颜色。
我已经用这些方法试过了。
但结果是显示为一个空白的图像。
帮助我...
private void bunifuThinButton24_Click(object sender, EventArgs e)
{
Bitmap bmp1 = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());
bmp1.Save(@"C:\Users\...\New folder4\ xx.jpg");
}
Bitmap bmp1 = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());
创建一个新的空白位图图像,分辨率为pictureBox1的图形对象,你需要在这个位图中绘制你的图片框。你可以使用picturebox的DrawToBitmap函数来实现。
void bunifuThinButton24_Click(object sender, EventArgs e)
{
Bitmap bmp1 = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());
// fill in bitmap with the picturebox's backcolor
using (Graphics g = Graphics.FromImage(bmp1))
{
using (Brush drawBrush = new SolidBrush(pictureBox1.BackColor))
{
g.FillRectangle(drawBrush, new Rectangle(0, 0, bmp1.Width, bmp1.Height));
}
}
// draw picturebox on bitmap
pictureBox1.DrawToBitmap(bmp1, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
bmp1.Save(@"C:\Users\...\New folder4\ xx.jpg");
}