I am using this code:
Dim img as bitmap = DirectCast(Picturebox1.Image, bitmap)
--
I keep getting this stupid error after i debug!! it's driving me crazy.
how can i fix this?
Printable View
I am using this code:
Dim img as bitmap = DirectCast(Picturebox1.Image, bitmap)
--
I keep getting this stupid error after i debug!! it's driving me crazy.
how can i fix this?
Um, what stupid error? It would be handy to know what it is in order to suggest how to fix it. The code you've posted will work if the Image of the PictureBox refers to a Bitmap object and not otherwise. Any errors due to that specifically would happen at that point though, while you seem to be implying that your error happens later. Please provide ALL the relevant information and error messages are always relevant.
The image i am using is not a bitmap. I want to turn that image into a bitmap so that I can find the color of certain pixels at some coordinate.
If there is a way to do the above without using bitmaps, I will do that instead.
Here is a screenshot of the error:
http://i48.tinypic.com/288d8n.png
Casting is not a way to convert an object from one type to another. If the object is not a Bitmap then you can't cast it as a Bitmap. If you want to create a Bitmap then you will have to actually create a Bitmap object of the appropriate dimensions and then use GDI+ to draw the original Image onto the Bitmap.
That said, I'm not sure that that is the immediate issue based on that error message. Have you actually read that Exception Assistant window and done what it says? There's a link on that that says "View Detail". Have you clicked it to view the details? It tells you to see the InnerException for details. Have you done that?
If you want us to help you fix the problem then does it not make sense to provide us with all the relevant information that the IDE gives you to help you fix the problem? Do you expect a diagnosis from a doctor without explaining the symptoms? I wouldn't like to be your mechanic either.