Scaling/Flipping Image

Does anybody know of a built-in method or have a way that I can flip an image in the way I want with scaling. Basically, I want to be able to scale an image with something like this:

g.DrawPicture Scale(OriginalPicture,ScaleX,ScaleY), 0,0

The scale of 1 would mean the same dimensions as the OriginalPicture. The scale of 0 would mean no picture. And the scale of -1 would mean it flips it horiz or vert depending on whether it is scale x or y?

Thanks

There’s nothing “built-in” but you can write your own extension to the picture class. I’ve done that so that I can resize a picture with a percent instead of the normal convoluted way (which includes the ability to crop, etc.).

For flipping, there are third party modules such as the ImagePlayEffects library (pure Xojo code, not a plugin).

[quote=73350:@Marc Zeedar]There’s nothing “built-in” but you can write your own extension to the picture class. I’ve done that so that I can resize a picture with a percent instead of the normal convoluted way (which includes the ability to crop, etc.).

For flipping, there are third party modules such as the ImagePlayEffects library (pure Xojo code, not a plugin).[/quote]
What function do you use to scale backwards. I want to use negative values for the scale to flip. For example the x scale of 1 is the original scale but -1 is flipped and -.5 is flipped and scale half the size horizontally.

Thanks

you can scale with using all parameters of drawpicture method.

see
https://www.monkeybreadsoftware.net/faq-howtoscaleapictureproportinally.shtml

[quote=73375:@Christian Schmitz]you can scale with using all parameters of drawpicture method.

see
https://www.monkeybreadsoftware.net/faq-howtoscaleapictureproportinally.shtml[/quote]
Looks great. Thanks!

A Xippet was posted on the Xippets website to scale pictures. Not used it myself but you can have a look https://www.boxedbyte.com/xippet-172

Thanks. I have got scaling sorted. I just need to flip the image, either vertically or horizontal.

Have you tried, speedwise, drawing one row (or column for vertical flip) at a time?

for i = 0 to height
   newpic.drawpicture(oldpic, 0, height-i, width, 1, 0, i, width, 1)
next

Otherwise, make sure you use RGBSurface instead of Graphics.Pixel.

Oops, should be “column for a horizontal - Y axis - flip”.

Another approach would be to use GetData to put the picture data into a MemoryBlock and move chunks of data around, calculating the offsets. A flip on the Y axis would be tedious this way, but flipping top-too-bottom should be fast.

[quote=73399:@Tim Hare]for i = 0 to height
newpic.drawpicture(oldpic, 0, height-i, width, 1, 0, i, width, 1)
next[/quote]
Thanks

Pretty sure that the WINAPI call BitBlt under Windows allows you to specify negative parameters to achieve a one line flip/inversion

What platform are you targeting?

[quote=73421:@Jeff Tullin]Pretty sure that the WINAPI call BitBlt under Windows allows you to specify negative parameters to achieve a one line flip/inversion

What platform are you targeting?[/quote]
Windows, Mac and Linux. Xojo only lets me use the width of 1 as a minimum.

Thanks

I would look into context translations. On the Mac, CoreGraphics has translations that can scale and flip the context, I’m sure under Windows there are similar translations.

If you your time is worth $10 per hour, and you already spent 4 hours thinking about it, you could buy the MBS Picture plugin on its own at 39EUR
It has an invert and HMirror function , plus a lot of other goodies, and its cross platform.

Sam… would you be willing to post some working examples of Flip, Rotate using CoreGraphics??? :slight_smile: