bmp没有关闭或Dispose(),不能写。解决方式:
Bitmap newBmp = new Bitmap(bmp);
bmp.Dispose();
newBmp.Save(@"c:\6.bmp");
或者改名存储,然后Dispose(),然后改回来。
Bitmap newBmp = new Bitmap(bmp);
bmp.Dispose();
newBmp.Save(@"c:\6.bmp");
或者改名存储,然后Dispose(),然后改回来。
Bitmap bmp = new Bitmap(fs);
fs.Close();
bmp.SetPixel(1, 2, System.Drawing.Color.RoyalBlue);
bmp.Save(@"c:\6.bmp", ImageFormat.Bmp);
# 复制代码
private void ConstructFromResourceSaveAsGif(PaintEventArgs e)
{ // Construct a bitmap from the button image resource.
Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp"); // Save the image as a GIF.
bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif); // Construct a new image from the GIF file.
Bitmap bmp2 = new Bitmap("c:\\button.gif"); // Draw the two images.
e.Graphics.DrawImage(bmp1, new Point(10, 10));
e.Graphics.DrawImage(bmp2, new Point(10, 40)); // Dispose of the image files.
bmp1.Dispose();
bmp2.Dispose();
}
Bitmap bmp = new Bitmap(@"C:\6.BMP"); //这里bmp对象已经把6.bmp文件给独占了,即使是bmp来覆盖都不行的
bmp.SetPixel(像素x, 像素y, 更改后的像素信息);
bmp.Save(@"c:\6.bmp", ImageFormat.Bmp);搂主改成下面代码,应该没有问题了:
Bitmap sourceBmp = new Bitmap(@"C:\6.BMP");
sourceBmp.SetPixel(10, 10, Color.Red);
sourceBmp.SetPixel(11, 11, Color.Red);
sourceBmp.SetPixel(12, 12, Color.Red);//再创建一个内存位图
Bitmap memoryBmp = new Bitmap(sourceBmp.Width, sourceBmp.Height);//把sourceBmp图象绘制到这个新的内存位图上
Graphics g = Graphics.FromImage(memoryBmp);
g.DrawImage(sourceBmp, 0, 0);
g.Dispose();//释放掉原位图独占的资源
sourceBmp.Dispose();//把内存位图覆盖6.bmp保存
memoryBmp.Save(@"C:\6.BMP", ImageFormat.Bmp);
memoryBmp.Dispose();