"Value does not fall within expected range"

bonedoc

Well-known member
Joined
May 4, 2006
Messages
112
Programming Experience
Beginner
I am tryng to save an image from a picturebox like this:

picturebox1.image.save("Path")

and I keep getting the "Value does not fall wthin expected range" error. Does anyone know what this is? It seems like the image would be valid if the picturebox is showing it.
 
Image.Save method doesn't throw such exception, it must be something else.
 
Image.Save method doesn't throw such exception, it must be something else.

ahh....I was actually getting this error when saving it to the stream. I thought it was just the image format in the picturebox image, or that its header was lost. I was saving images to the stream, just like you showed me. Works great. Then I tired to save the picturebox image to a stream by saving it as a bitmap first. that is where the error started. do you know the best way to extract an image off a picturebox and save it to a stream?
 
I have no idea how you do that. Any chance of sharing information needed to reproduce the problem?
 
I have no idea how you do that. Any chance of sharing information needed to reproduce the problem?

Yeah, it is simple..I am on my PDA, but here it goes;

dim bmp as new bitmap(picturebox1.image)

bmp.save(tcp.getstream, imaging.imageformat.bmp)


seemslike it would work just the same.
 
Have a look at this and see if you can add it up: http://www.vbdotnetforums.com/showthread.php?t=10714
Also don't access the Picturebox from a different thread if you were doing that.

No luck there. I have tried everything. I am using the exact same code to send the image from a filestream, and it works...but the same code pulling from a picturebox does not work. I don't know what it would be. Any ideas?
 
It's the same as the thread I linked in previous post, find a way to leave the picturebox out of the puzzle, it locks the image.
Edit: With regards to not accessing the picturebox control on a different thread you could use the PictureBox.DrawToBitmap method perhaps, but there is no need to.

By the way I got the full plethora of exceptions when trying different things out, but the one you originally posted I have not been able to reproduce.
 
Last edited:
Back
Top