How to display a picture in perspective?

What would be the simplest way to display a picture in perspective, using the Canvas or Imagewell control?

I’m trying to achieve this: open a picture, then calculate a perspective and display the result in a new control.

Plugins or not?
Mac or Windows?

basically a picture from picture.
have you tried rgbsurface?
https://documentation.xojo.com/api/graphics/rgbsurface.html

You should take into account the foreshortening. You did not. The effect you produced is a forelengthening. Proper depth perception requires foreshortening, i.e., the width should be reduced to e.g. half of the original width; you kept it constant.

If you want to do it in straight Xojo code:

Take big picture and draw it into a new picture which is slightly less wide
Now it is foreshortened.

Next, loop from left to right , pixel by pixel , and copy a vertical slice of the foreshortened image

.drawpicture that into a new image as the same x location, but at a vertical size which has been reduce by some amount proportional to the x co-ordinate.
And centred at the centre

At the extreme, its like this:

ABCDEFG
ABCDEFG
ABCDEFG

becomes

ABDG
ABDG
ABDG

And then becomes

AB
ABD
ABDG
ABD
AB

If plugins are an option, Einhugur PictureEffectsRaw can do this (though I’m not sure how to implement it)

3 Likes

I have used this Einhugur plugin to turn a square picture into a 3d-looking cube, with varying shading added to certain sides to look like the light angle varies.

3 Likes

I third the Enihugur plugin.

How is 3x3 matrix transformation done with Einhugur plugins?
Did only find rotate, scale in PictureEffects
Unfortunately the demo does not work due to missing RawBitmapConverter.

For macOS/iOS, you may also use Core Image filter via CIFilterPerspectiveTransformWithExtentMBS class.

I wanted to do that to create Windows 10 icons, then I changed my mind and used this instead:

Argh ! I am late, this is Jan 2021; here’s cover for March 2021 (and different custom icon)

image

web site:

http://www.xdevmag.com/

Yeah. It looks like you used a 3-point perspective. At each point the side of a cube should vanish in perspective, as parallel lines do in perspective. So this requires 3 matrix skew conversions as far as I can judge. And shading is very helpful to accentuate these.

The function is shape distort.

Thanks a lot Sam!
I would have never been able to find this…

1 Like

Thanks, Christian, this seems to be my best option. I’m trying to adapt your ‘Simple Filter with Picture’-example, so that when I move the slider, it will change the perspective. But it’s not clear to me which parameter I have to change and how. Any ideas?

As someone who’s worked with Core Image for over a decade now, I would really encourage you to consider other options.

Core Image was fantastic (although it has always been a little hard to get maximum performance), but in the last half decade it is all too easy for Core Image to fail, and with the lack of debugging options, you can waste a lot of time.

For example in Mojave, some customers would get a black image when they tried to save the image, but only if their machine had been running for 10 or more days. I had to rewrite the entire save routine, because the combination that’s worked for 5 years, no longer does.

1 Like

You just install the TypeLib that comes with it. Is where RawBitmap and RawBitmapConverter comes from. You also need to install the TypeLibF that also comes with it.

Did put all three demo files into plugin folder.
Or should they go elsewhere?

Anyway, thanks for the info. Will try again.

Only plugin files (.xojo_plugin) goes in the Xojo plugin folder, nothing else belongs there.