I’ve looked into this, and have mostly found older threads. I’m hoping since, there are some streamlined solutions, but I haven’t been able to find any. Is there any way to draw an image flipped? Or rather, I should say, what is the current, most streamlined way to draw an image flipped? This may get a little weirder, as I am also trying to consider drawing part of an image flipped.
Hey there - I mean flipped (mirrored), either over horizontal or vertical axis, like in other environments scaling to -1. I did find some methods in posts, many pointed to third party plug ins (which I’m not against), but were also quite old, so I was seeing if there were any newer methods that I’m just not discovering.
Sub Action() Handles Action
// Rotate the cSource contents
// and place it into cTarget
Dim x,y As Integer
Dim aColor As Color
Dim sourceSurf As RGBSurface
Dim targetSurf As RGBSurface
Dim pTarget As New Picture(pSource.Width,pSource.Height)
sourceSurf = pSource.RGBSurface
targetSurf = pTarget.RGBSurface
For x = 0 To pSource.Width
For y = 0 To pSource.Height
targetSurf.Pixel(x,y) = sourceSurf.Pixel(y,x)
If UserCancelled Then Exit
If UserCancelled Then Exit
cTarget.Backdrop = pTarget
pSource is a Picture Property
I pasted the image in the left Canvas, the right canvas is the result of the code execution.
Wow I think so! For the purposes of testing all this, yes. I actually didn’t mean for someone to blast out code, but rather point me in the right direction, but I can’t thank you enough for testing that out and offering an already working solution! I’ll try this out in a little while and see if I can integrate it into what I’m doing. I’ll have to see what additional weirdness comes from flipping a PART of an image, but I’ll see if I can get this working first as a test!
Awesome. I will keep you updated. These images are small. It should not much matter.
One rather simple solution occurred to me for the flip/picture part. I imagine I could convert that flipped surface into a picture and store it, yeah? If so, when I load a new image to the picker, I could just make three copies (default, flip h, flip v, and flip h&v) as pictures. Then, when I’m using the picker, just draw the appropriate picture part based on flip selection controls.
Another possibility is that I could just make a huge array of tile pictures. I could break the picker into all of the potential images, and all their respective potential flips (these would be 8x8px pieces…but lots of them), then build a pointer array of some sort to know what to draw.
Sub Paint(g As Graphics, areas() As Rect) Handles Paint
It’ll be a LITTLE more of a challenge of logic to draw parts from this.
I’m trying to figure out the best way to handle this. Either I can do it mathematically or via individual assets. Like - the picker will always remain static. When drawing a part of the picker, I have no flips easy, figured out mathematically. But if the stamp is supposed to be flipped vertically, I either can have a iteration of the picker picture, from which it is pulled (in which case, it has to do the math to translate to the new position…if it was on the top row, it would now be on the bottom row, etc), OR I could get the piece of the picker, create a stamp-sized asset out of it, then draw the stamp sized asset with the flip.
I think I can work my way through either, but any cliffs I might be looking at with either solution? Anything I’m not considering? Thanks!
if you create a new picture object u can use the .graphics property to draw a picture into too.
means you can create a method picNew=Flip(picOld) with the same calls in the paint event.
graphics also have a few clip methods. or use the arguments in drawpicture itself to crop.
Thanks - I’m not sure I follow. If I use g.DrawPicture for my stamp, I know I can crop down to the piece I need. Now I know how I can set up a flip of the whole picture. Is there an easy way to define the cropped area, THEN flip just the crop to show? For instance, If I have a 1024x1024px image, and I’m only looking at a 32x32px area in the top left corner, I crop to that area so I just have the 32x32px result, then flip THAT accordingly? Otherwise, I have to then read from the top RIGHT corner of the fully flipped image, right?
Graphing Sign Waves.xojo_binary_project
Interactive Objects in a Canvas
Object2D Text Rotation.xojo_binary_project
Saving and Load Vector Graphics.xojo_binary_project
Hey there - yes, I’m slowly sort of working through a lot of things - with the help here in addition to the resources like what you’re describing, I’ve been making a lot of progress quickly! But there are still a lot of deep corners to examine. I actually have what I’m trying to accomplish mostly working. However, the code in the paint event for this canvas iterates through stamps to draw from a list, all of which may have different flip parameters. This is producing unexpected results upon iteration (it works fine for non-flipped things, reading coordinates from the table, so I know the table is working great, but beyond the first flipped, flipped stamps don’t work as they’re supposed to).
I have this suspicion that during the loop, setting the translation/scale are translating/scaling based on the last setting…so if in the first iteration, I set the translation and scale to get a flip, then in the next iteration, I have another flipped stamp, it’s translating/scaling based on the already changed translation and changed scale. It’s not setting the translation or scale, it’s translating and scaling based on the current translation. Is this a correct assumption?
If so, what would be the proper way to reset the translation / scale at the end of an iteration?
I’ll continue to dig into some of those projects as well to see if they help. If anyone has any thoughts, that would be great!
I may try to handle this with Objects instead, but curious mind wants to know about above for the sake of learning
What I discovered is that for my purposes, I don’t need the translation. The following generally works. And yes, I found that I do have to reset the scale after drawing by writing again to negate it (affect the -1 scale by -1 to set it back to positive 1). Then, this seems to work for now.
'Draws the object on the canvas.
'original script- alone it works.
g.DrawPicture(Image, Left, Top)
//draws an image to the screen flipped vertically. It works.
g.Scale(1.0,-1.0) // reset the scale when we're done.
//draws an image to the screen flipped horizontally. It works.
g.Scale(-1.0,1.0) // reset the scale when we're done.
//draws an image to the screen flipped horizontally and vertically. It works.
g.Scale(-1.0,-1.0) // reset the scale when we're done.