4

このエラーを取得して画像を保存しようとしているときに、このエラー A generic error occurred in GDI+ を検索し、このフォルダーの書き込み権限を確認し、画像ファイルが他のもの(コードを含む)で使用されていないことも確認しましたが、画像をまだ保存しようとしています同じエラーが発生する、間違いはどこですか

public partial class AdsMaster : Form
    {
        OpenFileDialog ofd=null;
        public AdsMaster()
        {
            InitializeComponent();
        }

    private void browseButton_Click(object sender, EventArgs e)
    {
        ofd = new OpenFileDialog();
        ofd.Filter = "image files|*.jpg;*.jpeg;*.gif;*.png;*.bmp";
        DialogResult dr = new DialogResult();
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            Image img = new Bitmap(ofd.FileName);//create the bitmap
            string imgName = ofd.SafeFileName;
            txtImagePath.Text = imgName;
            pictureBox1.Image = img.GetThumbnailImage(350, 350, null, new IntPtr());
            ofd.RestoreDirectory = true;
            img.Dispose();
        }
    }

    private void saveImage_Click(object sender, EventArgs e)
    {
        String str = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
        string path = str + "\\Image\\";
        Image img = new Bitmap(ofd.FileName);
        string imgName = ofd.SafeFileName;
        try
        {
               img.Save(path + imgName); //getting error at this line 
               MessageBox.Show("Image is saved");
               img.Dispose();  // dispose of your image                   
        }
        catch(Exception err)
        {
            MessageBox.Show(err.Message.ToString());
        }

      }        
} 
4

2 に答える 2