pictureBox.image.save方法怎样用

king19840811 2008-12-14 02:27:46
这样获得文件名后string pictureName = System.IO.Path.GetFileName(pictureopenFileDialog.FileName);
怎样保存到一个文件夹中。
...全文
1030 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
net5i 2008-12-14
  • 打赏
  • 举报
回复
搂主去掉:System.IO.Path.GetFileName就可以了:
this.pictureBox.Image.Save(pictureopenFileDialog.FileName);
king19840811 2008-12-14
  • 打赏
  • 举报
回复
啥原因啊 string pictureName = System.IO.Path.GetFileName(pictureopenFileDialog.FileName);
this.pictureBox.Image.Save(@"c:\xxx.bmp");我这样用的能行吗
net5i 2008-12-14
  • 打赏
  • 举报
回复
搂主可以看看我在下面贴中的详尽代码回复:
http://topic.csdn.net/u/20081206/09/9a28f8b3-48de-499c-83b7-54e0b4499b93.html
net5i 2008-12-14
  • 打赏
  • 举报
回复
噢,呵呵,我就知道搂主保存bmp有异常
king19840811 2008-12-14
  • 打赏
  • 举报
回复
这上面查了。保存的时候提示是GUI+发生一般性错误不知道啥意思
slimfeng 2008-12-14
  • 打赏
  • 举报
回复
网络太慢,还以为第一次没有回复成功,发了两次。
请楼主参考。
slimfeng 2008-12-14
  • 打赏
  • 举报
回复
保存路径是可以设置的。
以下是msdn中Image类Save方法的调用例子。

Bitmap image1;

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.");
}
}

private void Button5_Click(System.Object sender, System.EventArgs e)
{
try
{
if (image1 != null)
{
image1.Save("c:\\myBitmap.bmp");
Button5.Text = "Saved file.";
}
}
catch(Exception)
{
MessageBox.Show("There was a problem saving the file." +
"Check the file permissions.");
}

}




slimfeng 2008-12-14
  • 打赏
  • 举报
回复
不太明白楼主的意思。
以下代码是msdn中Image类Save方法的例子。

Bitmap image1;

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.");
}
}


private void Button5_Click(System.Object sender, System.EventArgs e)
{
try
{
if (image1 != null)
{
image1.Save("c:\\myBitmap.bmp");
Button5.Text = "Saved file.";
}
}
catch(Exception)
{
MessageBox.Show("There was a problem saving the file." +
"Check the file permissions.");
}

}


king19840811 2008-12-14
  • 打赏
  • 举报
回复
是啊
king19840811 2008-12-14
  • 打赏
  • 举报
回复
老哥我想要picturebox直接保存啊。image.Save("保存全路径", System.Drawing.Imaging.ImageFormat.Bmp);//第二个参数是保存格式,根据自己需要修改
保存全路径可以替换成当前项目的文件夹吗?
net5i 2008-12-14
  • 打赏
  • 举报
回复
搂主是不是调用出异常了,而不知道怎么调用?
pp_shy 2008-12-14
  • 打赏
  • 举报
回复

Image image = Image.FromFile("图片文件全路径");
image.Save("保存全路径", System.Drawing.Imaging.ImageFormat.Bmp);//第二个参数是保存格式,根据自己需要修改

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧