这样获得文件名后string pictureName = System.IO.Path.GetFileName(pictureopenFileDialog.FileName);
怎样保存到一个文件夹中。

解决方案 »

  1.   


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

  2.   

    老哥我想要picturebox直接保存啊。image.Save("保存全路径", System.Drawing.Imaging.ImageFormat.Bmp);//第二个参数是保存格式,根据自己需要修改
    保存全路径可以替换成当前项目的文件夹吗?
      

  3.   

    不太明白楼主的意思。
    以下代码是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.");
        }}
      

  4.   

    保存路径是可以设置的。
    以下是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.");
        }}
     
      

  5.   

    这上面查了。保存的时候提示是GUI+发生一般性错误不知道啥意思
      

  6.   

    噢,呵呵,我就知道搂主保存bmp有异常
      

  7.   

    搂主可以看看我在下面贴中的详尽代码回复:
    http://topic.csdn.net/u/20081206/09/9a28f8b3-48de-499c-83b7-54e0b4499b93.html
      

  8.   

    啥原因啊    string pictureName = System.IO.Path.GetFileName(pictureopenFileDialog.FileName);
                this.pictureBox.Image.Save(@"c:\xxx.bmp");我这样用的能行吗
      

  9.   

    搂主去掉:System.IO.Path.GetFileName就可以了:
    this.pictureBox.Image.Save(pictureopenFileDialog.FileName);