如何在firemonkey c ++中获得Image的最大居中矩形区域

时间:2017-11-16 22:53:32

标签: c++ firemonkey

我试图在矩形区域裁剪图像,用它填充一个圆圈,但我找不到任何方法来做到这一点。 Tt说我的代码结果不正确,图像放置不好。我不知道我的代码有什么问题。

我看到了一些例子,但它们并不适合我。

以下是我访问过的网站:

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

注意:代码应该用FMX whit C ++编写,它应该在所有平台上运行。 TCircle将WrapMode分配给TileStrech。

int CropBitmap(TBitmap* in, TBitmap* out)
{
  if (!in or !out)
  {
    return 1;
  }

  TBitmap * bm = new TBitmap();

  int origH = in->Height;
  int origW = in->Width;
  TRect rect;
  int defH, defW;
  if (origH > origW)
  {
    bm->Height = origW;
    bm->Width = origW;

    int factor = (origH - origW) / 2;
    rect.Top = factor;
    rect.Left = 0;
    rect.Right = origW;
    rect.Bottom = factor + origW;

    bm->CopyFromBitmap(in, rect, 0, 0);
  }
  else if (origW > origH)
  {
    bm->Height = origH;
    bm->Width = origH;

    int factor = (origW - origH) / 2;
    rect.Top = 0;
    rect.Left = factor;
    rect.Right = factor + origH;
    rect.Bottom = origH;

    bm->CopyFromBitmap(in, rect, 0, 0);
  }
  else
  {
    bm->Assign(in);
  }

  out->Assign(bm);
  delete bm;
  return 0;
}

此代码的结果是:     The bitmap is not well placed in a Circle

我的目标是获得这样的裁剪图像: image croped

解决

我有一个解决此问题的方法

{{1}}

对我来说运行良好。

0 个答案:

没有答案