dwieringa
asked on
Swapping Pictures within PictureBox
My guess is that this is very simple.
I have a PictureBox and when the user clicks certain button on my Form I need to change the Picture within the PictureBox.
I will have two pictures that I will be swapping between.
I need code to store two pictures (which happen to come from a property called Image() of an control I purchased...which grabs images from a webcam) and at the click of a button change from one to the other in the PictureBox.
I have a PictureBox and when the user clicks certain button on my Form I need to change the Picture within the PictureBox.
I will have two pictures that I will be swapping between.
I need code to store two pictures (which happen to come from a property called Image() of an control I purchased...which grabs images from a webcam) and at the click of a button change from one to the other in the PictureBox.
ASKER
bruintje:
No, sorry to mislead you.
I copy the images into the Picture box with:
thePictureBox.Picture = myPreviewForm.ControlName. Image
Once I copy it into the PictureBox I can't safely go back to the control. I want to move it into "holding" data items. One will be the raw image. The other I will change various pixels using the PSet function -- think of this as "decoration" on top of the image. I want the user to be able to toggle between the raw and decorated images.
Is this clearer?
No, sorry to mislead you.
I copy the images into the Picture box with:
thePictureBox.Picture = myPreviewForm.ControlName.
Once I copy it into the PictureBox I can't safely go back to the control. I want to move it into "holding" data items. One will be the raw image. The other I will change various pixels using the PSet function -- think of this as "decoration" on top of the image. I want the user to be able to toggle between the raw and decorated images.
Is this clearer?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
.... you got it there Idle_Mind was still typing :-)
indeed using a copy to take a step back to the original or one step back in the addition of decoration to the image
indeed using a copy to take a step back to the original or one step back in the addition of decoration to the image
ASKER
Idle Mind:
Thanks.
One question... What is the significance of the "Set" each time we are copying the images? Does it have something to do with copying by value vs by reference?
One comment... At first this "didn't work" for me (I probably wasn't specific enough). I use PictureBox.pset to alter various pixels in my "decorated" version. Following your pattern above, I kept losing these decorations. I found I need to use Picture1.Image instead of Picture1.Picture if I want to copy these drawing changes.
Thanks.
One question... What is the significance of the "Set" each time we are copying the images? Does it have something to do with copying by value vs by reference?
One comment... At first this "didn't work" for me (I probably wasn't specific enough). I use PictureBox.pset to alter various pixels in my "decorated" version. Following your pattern above, I kept losing these decorations. I found I need to use Picture1.Image instead of Picture1.Picture if I want to copy these drawing changes.
We use Set because we are dealing with an Object.
Here is another way to do your "decorations"...
Option Explicit
Private overlayOn As Boolean
Private Sub Command1_Click()
overlayOn = Not overlayOn
Picture1.Refresh
End Sub
Private Sub Picture1_Paint()
If overlayOn Then
Picture1.Line (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight), vbRed
End If
End Sub
Option Explicit
Private overlayOn As Boolean
Private Sub Command1_Click()
overlayOn = Not overlayOn
Picture1.Refresh
End Sub
Private Sub Picture1_Paint()
If overlayOn Then
Picture1.Line (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight), vbRed
End If
End Sub
ASKER
Idle Mind:
Thanks. I actually use something like that for other markings on the images. The stuff I'm doing with PSet looks at each pixel and then paints it a different color based on rules. Over a large area, this is too slow for frequent repainting. ...which is why I'm storing that in the StdPicture and toggling it via the picture swap.
Thanks again.
Dave
Thanks. I actually use something like that for other markings on the images. The stuff I'm doing with PSet looks at each pixel and then paints it a different color based on rules. Over a large area, this is too slow for frequent repainting. ...which is why I'm storing that in the StdPicture and toggling it via the picture swap.
Thanks again.
Dave
----------
from your comment i assume Image() is an array so what you can do on the button click is loading one picture from the array
have a public module variable blnFirstIsCurrent as boolean
then in your buttonclick try something like
if blnFirstIsCurrent then
With myPictureBox
Set .Picture = Nothing
Set .Picture = Image(2)
.Refresh
End With
else
With myPictureBox
Set .Picture = Nothing
Set .Picture = Image(1)
.Refresh
End With
end if
----------
bruintje
share what you know, learn what you don't