winform程序曲线图输出错误
System.IO.MemoryStream ms = new System.IO.MemoryStream();image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
image.Save(string.Format("D:\\{0}.jpeg", ms), System.Drawing.Imaging.ImageFormat.Jpeg);
这样写的话每次只能保存一次图片,如果图片存在的话运行的时候总是报错。必须要把之前存在的图片删除后才可以,是不是要以文件流的形式才行啊?请问该怎么写?急用!!!! --------------------编程问答-------------------- 看看微软是如何描述的:
“不允许将图像保存到构造该图像的文件,这样会引发异常。”
private void Button1_Click(System.Object sender, System.EventArgs e)
{
try
{
// Retrieve the image.
image1 = new Bitmap(@"C:\Documents and Settings\All Users\"
+ @"Documents\My Music\music.bmp", true);
int x, y;
// Loop through the images pixels to reset color.
for(x=0; x<image1.Width; x++)
{
for(y=0; y<image1.Height; y++)
{
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
image1.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
PictureBox1.Image = image1;
// Display the pixel format in Label1.
Label1.Text = "Pixel format: "+image1.PixelFormat.ToString();
}
catch(ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
--------------------编程问答-------------------- 楼上正解 顶
补充:.NET技术 , C#