Crop Image Firemonkey C++

  

I’m trying to crop an image in a rectangular area, to fill a circle with it, but I cannot find any way to do that. Tt says that the result of my code is not correct and the image is not well placed. I don’t know what is wrong in my code.

I saw some examples , but they are not working for me.

Here are the sites I visited:

crop and align inserted BMP in Delphi

https://www.experts-exchange.com/questions/22142653/Crop-Bitmap-Image1.html

Delphi – how do I crop a bitmap "in place"?

How to crop an FMX TBitmap

Note: the code should be wrote in FMX whit C++, it should run in all platforms.
The TCircle have the WrapMode assign to TileStrech.

void __fastcall TForm9::Button1Click(TObject *Sender)
{
int X , Y , W , H;

if(Image1->Bitmap->Width >= Image1->Bitmap->Height)
{
H = Image1->Bitmap->Height;
X = (Image1->Bitmap->Width – Image1->Bitmap->Height) / 2;
Y = 0;
W = H;
}
else
{
W = Image1->Bitmap->Width;
X = 0;
Y = (Image1->Bitmap->Width – Image1->Bitmap->Height) / 2;
H = W;
}

TRect rect(X, Y, W, H);
TBitmap * bm = new TBitmap(W,H);
bm->CopyFromBitmap(Image1->Bitmap ,rect ,X,Y);

Circle1->Fill->Bitmap->Bitmap->Assign(bm);

Image2->Bitmap->Assign(bm);
delete bm;
}

The result of this code is:
The bitmap is not well placed in a Circle

My objetive is get an crop image like this :
image croped

Comments are closed.