0

I have 75*75 .png files, but I want them to show in a 150x150 sized ImageControl with transparent background. I currently use this code:

  FBitmapBufferLoadFromFile(...);
  icContactsDetails.Bitmap := TBitmap.Create(0, 0);
  icContactsDetails.Bitmap.Assign(FBitmapBuffer);
  icContactsDetails.Width := icContactsDetails.Bitmap.Width;
  icContactsDetails.Height := icContactsDetails.Bitmap.Height;
  icContactsDetails.Scale.X := 150 / icContactsDetails.Bitmap.Width;
  icContactsDetails.Scale.Y := 150 / icContactsDetails.Bitmap.Height;

I have the following questions:

1) How do I keep transparency? (Transparent area in .png is converted to white.) 2) Should I do the scaling outside the ImageControl to avoid setting width/height?

Tom
  • 3,587
  • 9
  • 69
  • 124

1 Answers1

3

Set

icContactsDetails.WrapMode:=TImageWrapMode.iwStretch

instead of scaling the control.

AvgustinTomsic
  • 1,809
  • 16
  • 22
  • I upvoted. But TImageControl / TImageControl.Bitmap do not have a wrapmode property. But I think TImage does. Will do some research! – Tom Jul 04 '13 at 11:33
  • 1
    I prefer using TImage than TImageControl. – AvgustinTomsic Jul 04 '13 at 12:15
  • 1
    @slotomo, does Bitmap have a wrapMode property? I think you meant `icContactsDetails.WrapMode` – Peter Jul 04 '13 at 12:19
  • 1
    If you use TImage then TImage have property WrapMode, if you use other controls with Fill property like TRectangle then WrapMode in on TBrushBitmap. – AvgustinTomsic Jul 04 '13 at 12:27
  • I switched over to TImage now as well. And both problem sovled now using TImage + WrapMode property :) – Tom Jul 04 '13 at 13:24