Does anyone know how to clear a FireMonkey TBitmap to completely transparent? BMP.Clear(TAlphaColorRec.Alpha) gives me a black image when it's drawn onscreen (eg to a paintbox, PaintBox1.Canvas.DrawBitmap(BMP ImageSrcRect, ImageDstRect, 1).

Does anyone know how to clear a FireMonkey TBitmap to completely transparent? BMP.Clear(TAlphaColorRec.Alpha) gives me a black image when it's drawn onscreen (eg to a paintbox, PaintBox1.Canvas.DrawBitmap(BMP ImageSrcRect, ImageDstRect, 1).

At the moment I'm using the above code to clear to White, which works, but there's no guarantee that really is the correct background colour. I'd actually much prefer the un-drawn-on bits remain transparent anyway.

Comments

  1. David Millington Alpha 255 is opaque, Alpha 0 is transparent.

    ReplyDelete
  2. Oh, I get what you're saying. I was thinking "full alpha" -> "fully transparent", whereas you are writing meaning the inverse, "full alpha" -> "alpha channel not zero" -> "fully opaque". My mistake; I was thinking in terms of transparency not opacity, and I incorrectly thought the .Alpha constant had 0 alpha.

    So, to clear a TBitmap to fully transparent, the correct code is actually BMP.Clear(TAlphaColorRec.Null) - not .Alpha. Solved. Very simple really and I feel slightly silly for asking now :)

    ReplyDelete
  3. Silly me. I did not notice that FMX BITMAP use PNG pixel format (ARGB/RGBA) and support native transparent drawing with alpha channel value.  BITMAP isn't windows bitmap or mac bitmap now?!
    Just learned and thank you for sharing all.

    ReplyDelete

Post a Comment