471,338 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Saving Image Problem

HI All,

I am having a problem saving the image in when using this code. The Language i am using is VB.NET 2005

Dim dlgImage As New OpenFileDialog

dlgImage.Filter = "Image Files (*.bmp, *.gif, *.jpg)|*.bmp;*.gif;*.jpg"

If dlgImage.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fs As New StreamReader(dlgImage.FileName)
Dim img As Image = Image.FromStream(fs.BaseStream)
fs.Close()
picImage.Image = img
End If
picImage.Image.Save(dlgImage.FileName, ImageFormat.Jpeg)

Here picImage is the Picture Box, Now the problem is that it gives me a error "A generic error occured in GDI+"

Please guide on the same, it would be of great help to me as i am already running late in Project.

Thanks in Advance,

Prashant Hirapara
Jun 19 '07 #1
2 1038
kenobewan
4,871 Expert 4TB
There are a number of reasons this could happen, try moving fs.Close()
down or comment out as a first step. HTH.
Jun 19 '07 #2
There are a number of reasons this could happen, try moving fs.Close()
down or comment out as a first step. HTH.
----------------------------------------------------------------------------------------------------------------------

HI Thanks man really its working .... i really appreciate yr prompt response..

Now there is a little problem with my code there is a case where the file i am opening let say "C:\Img.jpg" the same file i want to save it with the same name e.g.

"C:\Img.jpg".

Again the same error is coming and it is telling me that file is already opened by another process.

Can u guide me what is the best way to deal with this ... i am thinking of making an temporary image and then load it from there.

Thanks Again,

Prashant Hirapara
Jun 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by mchl gdbt | last post: by
4 posts views Thread by Michael Kennedy [UB] | last post: by
reply views Thread by Umesh | last post: by
5 posts views Thread by Thaynann | last post: by
6 posts views Thread by Jeff | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.