很简单,定义一个全局变量:public Bitmap pbmap;
然后所有的图都画在这个bitmap上面,保存时只要将pbmap保存就行了
pbmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
if (listBox1.Items.Count <= 0 || listBox1.SelectedItem == null)
{
return;
}
string thisimg = ((ListBox)sender).SelectedItem.ToString();
string name = txtfolderpath.Text + "\\" + thisimg;
if (File.Exists(name))
{
Bitmap map = new Bitmap(name);
Graphics g = Graphics.FromImage(pbmap);
g.DrawImage(map, 0, 0, pictureBox1.Width, pictureBox1.Height);
map.Dispose();
pictureBox1.Image = pbmap;
}
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string folderP = saveFileDialog1.FileName;
Image img = pbmap;
img.Save(folderP);
}
调用pictureBox的DrawToBitmap方法就可以了:
Bitmap bmp = new Bitmap(pictureBox1.BackgroundImage);
bmp.Save("c:\\1.bmp");
pictureBox1.Image = map 就行了呀。DrawImage 多余了。需要缩放的话,设置pictureBox的缩放模式就好了。
而且从你的代码来看copy 图像文件就好了。也用不着通过picutrebox来中转一下吧。
直接保存图片 map.Save("fileName");