I just did
Public This as new bitmap = picturebox1.image and then this error showed up
System.InvalidOperationExceptionbut it had nothing to do with that form, why is this?
Thank you
Printable View
I just did
Public This as new bitmap = picturebox1.image and then this error showed up
System.InvalidOperationExceptionbut it had nothing to do with that form, why is this?
Thank you
vb Code:
Public Class Form1 Public This As Bitmap Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load This = DirectCast(PictureBox1.Image, Bitmap) End Sub End Class
thanks but now I got another error.
This: picturbox2.Image = This
gives this error: ArgumentException was unhandled Invalid parameter
Thanks
works for me:
vb Code:
Public Class Form1 Public This As Bitmap Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load This = DirectCast(PictureBox1.Image, Bitmap) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox2.Image = This End Sub End Class
I would stay away from the word 'this' on the principle of the thing. It shouldn't have any meaning in VB, but it is the same as Me in C languages.
but how can I stop getting that error?
you''ll need to show us the relevant code
by paying attention to what you're doing... an IMAGE object is NOT A BITMAP... that's why there is a DIRECTCAST in the code Paul posted... seriously Paul, would it KILL you to post an explanation for the code you share once in a while? It doesn't do much good when they can't follow what's going on... anyways...
Since an Image is not a Bitmap, you can't simply assign one to the other... you have to cast or convert it somehow... in both directions. So if you have to use DirectCast to take an .Image and put it into a Bitmap object, doesn't it stand to reason that you would have to use DirectCast to take a Bitmap and put it into an .Image?
-tg