PixmapShape.SourceTop Example

Thanks to this post I’m learning about PixmapShape

The docs are not clear about PixmapShape.SourceTop (for me) and the example did not help.

[code]Example
This example reports the left, top, width, and height of the image that was assigned to the PixmapShape. This image was added to the project and the coordinates are 0, 0, 558, 372.

Dim p As Picture
Dim px As PixmapShape
p = New Picture(558, 372)
px = New PixmapShape(p)
px.Image = CarImage

Label1.Text = Str(px.SourceLeft)
Label2.Text = Str(px.SourceTop)
Label3.Text = Str(px.SourceWidth)
Label4.Text = Str(px.SourceHeight)[/code]

Of course I don’t have CarImage so I used several images (different sizes). I always get 0, 0, 558, 372. If I change the values here:

p = New Picture(558, 372)

then the values change.

I know my English is not great, maybe that’s why it doesn’t make sense to me. I changed the example to:

[code]Dim px As PixmapShape
px = New PixmapShape(CarImage)

Label1.Text = Str(px.SourceLeft)
Label2.Text = Str(px.SourceTop)
Label3.Text = Str(px.SourceWidth)
Label4.Text = Str(px.SourceHeight)[/code]

I get the width and height of the image I put instead of ‘CarImage’.

But still I don’t understand how or when px.SourceTop <> 0. I also see that px.SourceWidth = px.Width, same with Height.

Can anyone point me to more information/examples?

Thanks.

Those values let you crop the image. SourceTop takes that many pixels off the top. SourceLeft takes that many pictures from the left. SourceWidth crops the right by specifying how much of the left side of the image should be shown. SourceHeight crops the bottom by removing all but that many pixels vertically.

// given picture, p, with dimensions 300 x 300
px1 = new PixmapShape(p)
px1.SourceTop = 100   // removes 100 pixels from the top of the image

px2 = new PixmapShape(p)
px2.SourceLeft = 100  // removes 100 pixels from the left of the image

px3 = new PixmapShape(p)
px3.SourceWidth = 200   // removes 100 pixels (300 - 200) from the right of the image

px4 = new PixmapShape(p)
px4.SourceHeight = 100   // removes 200 pixels from the bottom of the image

Edit: the documentation is less than clear.

Thank you Tim. I didn’t know that I can assign values to SourceTop/Left/Width/Height, very interesting.

I did some test with some numbers and an image. As far as my tests go, the image is cropped but it preserves the original width and height.

A lot to learn. Thanks again.