Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the set up...
I have two picture boxes on a form. In PictureBox0 (PB0) I load a simple graphic (jpeg): (Green background with a red circle in the upper left corner). I want to click on the second Picture Box (PB1) and display the image from the PB0 flipped from the right to left. Eventually want to be able to display the image from PB0 flipped and rotated several different ways as the user clicks on PB1. Here is the code:

VB
Private Sub Picture1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Picture1.Click
        Picture1.Image = Nothing
        Application.DoEvents()
        Picture1.Image = Picture0.Image
        Application.DoEvents()
        Picture1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX) 
End Sub


This code actually works but only the first time. When you click a second or third time on PB1, the image flips between the original image in PB0 and the flipped image that I want.

Used the Application.DoEvents() to make sure the event was being forced.

The easy solution would have been: Picture1.Image =Picture0.Image.RotateFlip(RotateFlipType.RotateNoneFlipX) but that triggers an error message.

Seems like an easy thing to do but I cannot figure it out!!

Thanks for any help
Gary Vogel
Posted
Updated 25-Sep-10 7:58am
v2
Comments
DaveAuld 26-Sep-10 18:47pm    
Gary, is it "A generic error occurred in GDI+." error you are getting? i'm stumped by that one!

You might try something like:

VB
Private Sub Picture1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Picture1.Click
        Picture1.Image = Nothing
        Image copyImage = Picture0.Image.Clone() ' this breaks the link to Picture0
        copyImage.RotateFlip(RotateFlipType.RotateNoneFlipX)
        Picture1.Image = copyImage
End Sub


I have not tried this. Apologies if it doesn't work.

Without something like this all of your images actually point to the same image, which is why you are having problems, I think.

Good luck! :)
 
Share this answer
 
Hi Thanks for the help!
When I try this code it generates an error with the Image copyImage code stating that "Image is a type and cannot be used in an expression"
Perhaps there is an easy solution to that error???

But, I was able to solve the problem by loading the image into the picture box first and then rotating or flipping it rather than referencing the original picture box. Seems cumbersome but it worked.

Picture1.Image = New System.Drawing.Bitmap(CurDir() & "\Image1.jpg")
Picture1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)

Thanks again
Gary Vogel
 
Share this answer
 
Comments
Henry Minute 26-Sep-10 19:04pm    
Sorry, my fault. That's what you get for coding off the top of your head, rather than into a nice IDE where all the errors get pointed out (I slipped into C#).

The code should be:
PictureBox1.Image = Nothing
Dim copyImage As Image = PictureBox0.Image.Clone ' this breaks the link to Picture0
copyImage.RotateFlip(RotateFlipType.RotateNoneFlipX)
PictureBox1.Image = copyImage

I have tested it and it works.
You are right, it worked!! And your code makes more sense rather than having to load an image from a disk each time!! I should have been able to figure out that Dim statement!

THANKS SO MUCH!!!
Gary Vogel
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900