|
-
May 15th, 2012, 07:04 PM
#1
Thread Starter
Junior Member
Picturebox to bitmap? errors?!
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?
-
May 15th, 2012, 07:29 PM
#2
Re: Picturebox to bitmap? errors?!
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.
-
May 15th, 2012, 08:17 PM
#3
Thread Starter
Junior Member
Re: Picturebox to bitmap? errors?!
 Originally Posted by jmcilhinney
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:
-
May 15th, 2012, 08:38 PM
#4
Re: Picturebox to bitmap? errors?!
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?
-
May 15th, 2012, 11:45 PM
#5
Thread Starter
Junior Member
Re: Picturebox to bitmap? errors?!
 Originally Posted by jmcilhinney
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?
And if I want to use a png as my image?
EDIT: even if i use a bitmap image i still get the error!
-
May 16th, 2012, 12:03 AM
#6
Re: Picturebox to bitmap? errors?!
 Originally Posted by yoni201
And if I want to use a png as my image?
Read the first paragraph of my previous post.
 Originally Posted by yoni201
even if i use a bitmap image i still get the error!
Read the second paragraph of my previous post.
-
May 16th, 2012, 12:06 AM
#7
Thread Starter
Junior Member
Re: Picturebox to bitmap? errors?!
 Originally Posted by jmcilhinney
Read the first paragraph of my previous post.Read the second paragraph of my previous post.
Yes, I read it. it's hard to tell what the problem is.
Could you send me a complete source of the working project?
thanks.
-
May 16th, 2012, 12:39 AM
#8
Re: Picturebox to bitmap? errors?!
 Originally Posted by yoni201
Yes, I read it. it's hard to tell what the problem is.
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|