gdi+ で汎用エラーが発生しました

gdi+ で汎用エラーが発生しました

出たりだ無かったり

1.vbでPictureBoxにファイルを読み込む
                Dim fs As System.IO.FileStream
                fs = New System.IO.FileStream(filename _
                      , System.IO.FileMode.Open _
                       , System.IO.FileAccess.Read)
                Try
                    PictureBox1.Image = System.Drawing.Image.FromStream(fs)
                Catch argEx As ArgumentException
                    MsgBox(argEx.Message, MsgBoxStyle.Information)                End Try
                fs.Close()
2.またはクリップボードからはり付けで

 PictureBox1.Imageを書き込むと
gdi+ で汎用エラーが発生しましたが発生する

原因は、どうもPictureBox1にロックがかかるみたい、、、、

で対応は
一端bitmapに読み込んで出力
            Dim bmp As Bitmap = New Bitmap(PictureBox1.Image)
            Dim fs As System.IO.FileStream = New IO.FileStream(fname, IO.FileMode.Create)
            bmp.Save(fs, Imaging.ImageFormat.Jpeg)
            fs.Close()