private void p1_Paint(object sender, PaintEventArgs e)
{
//dgvCase.ClearSelection();
//显示绘制的图形
//将Image中保存的图像,绘制出来
Graphics g = p1.CreateGraphics();
if (backImage != null)
{
g.Clear(Color.White);
g.DrawImage(backImage, p1.ClientRectangle);
try
{
backImage.Save("d:\\2.bmp", ImageFormat.Bmp);
}
catch (Exception ba)
{
MessageBox.Show(ba.Message);//总提示GDI+一般性错误。
}
}
}
}
但我做的另外一个保存图像的DEMO中也是这样写的,就没有这种错误提示。郁闷。
{
//dgvCase.ClearSelection();
//显示绘制的图形
//将Image中保存的图像,绘制出来
Graphics g = p1.CreateGraphics();
if (backImage != null)
{
g.Clear(Color.White);
g.DrawImage(backImage, p1.ClientRectangle);
try
{
backImage.Save("d:\\2.bmp", ImageFormat.Bmp);
}
catch (Exception ba)
{
MessageBox.Show(ba.Message);//总提示GDI+一般性错误。
}
}
}
}
但我做的另外一个保存图像的DEMO中也是这样写的,就没有这种错误提示。郁闷。
解决方案 »
- 高手请看问题:BindingSource ,ErrorProvider 使用的问题
- dllforvc.dll谁有啊?
- PublicKeyToken=b77a5c561934e089”类型的权限已失败。]
- 多线程引起的奇怪问题!
- 求一个vs20005的下载地址,谢谢了,找了半天没找到一个能用的.急坏了呀.
- 数据库读写重System.FormatException: 输入字符串的格式不正确。
- 字符串Split问题.
- 寻找青岛地区.NET高手
- 帮忙!!
- 如何通过textbox实现向数据库的更新(update)操作 本人菜鸟求解
- 谁能提供一个可用于WinForm的RadioButtonlist控件
- 有没那个朋友帮忙解释一下这段代码的算法(图像缩放)?
换成别的事件.让Save不在一直执行.
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Bitmap backImage = new Bitmap(500, 500);
Graphics g = pictureBox1.CreateGraphics();
if (backImage != null)
{
g.Clear(Color.White);
g.DrawImage(backImage, pictureBox1.ClientRectangle);
try
{
backImage.Save("d:\\2.bmp", ImageFormat.Bmp);
}
catch (Exception ba)
{
MessageBox.Show(ba.Message);//总提示GDI+一般性错误。
}
} }
}
}
pictureBox1.CreateGraphics();
有点
如果你的backImage是 Image.FormFile(@"d:\\2.bmp"); 来的把..你再正使用这个文件呢取图片用这样取看看
Image backImage = Image.FromStream(new MemoryStream(File.ReadAllBytes(@"c:\1.png"))); backImage.Save(@"c:\1.png", ImageFormat.Png);
大体上这样的:与生成bitmap位图的方式有关其中bmp2是你要用的位图,
Bitmap bmp = new Bitmap(filePath);
//新建第二个bitmap类型的bmp2变量,我这里是根据我的程序需要设置的。
Bitmap bmp2 = new Bitmap(1024, 768, PixelFormat.Format16bppRgb555);
//将第一个bmp拷贝到bmp2中
Graphics draw = Graphics.FromImage(bmp2);
draw.DrawImage(bmp,0,0); 这时你保存就不会发生GDI+错误
bmp2.Save(path);