Drewski7280
Drewski7280

Reputation: 53

How to convert TImage and TImageControl coordinates to underlying bitmap coordinates?

I'm working on a small C++Builder FireMonkey project that uses both TImage and TImageControl components.

I'm trying to display the RGB pixel colors of the underlying bitmaps when the mouse moves over both of these controls. The online help has a couple of functions called ConvertLocalPointTo and ConvertLocalPointFrom. C++Builder help doesn't have any information on these routines.

I also noticed that TImageControl has a MarginWrapMode property which allows you to center and fill the bitmap to the control, whereas TImage doesn't.

What are they defining as a local point? Is that the point in the control, or the point in the bitmap? When you look in the help file, the typical Embarcadero help message is shown:

Embarcadero Technologies does not currently have any additional information.

Does anyone have a programming example of how to convert between the 2 coordinate systems?

Upvotes: 2

Views: 74

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597916

When a Bitmap fills the client area of a TImage/Control, converting a TImage-local coordinate into a TBitmap-local coordinate is fairly simple. Calculate a ratio of the TImage X coordinate to the TImage width, and then apply that same ratio to the TBitmap width to get the TBitmap X coordinate, eg:

BitmapX := (ImageX / ImageWidth) * BitmapWidth

Then, do the same for the Y coordinates relative to the heights.

Obviously, if the TBitmap does not fully fill the TImage, then you will have to subtract any margins, offsets, etc from the ImageX/ImageY and ImageWidth/ImageHeight as needed.

Upvotes: 0

Related Questions