# Drawing TBitmap

**URL:** <https://forum.castle-engine.io/t/drawing-tbitmap/992>\
**Category:** 2D\
**Created:** [November 24, 2023, 4:54pm UTC](https://forum.castle-engine.io/t/drawing-tbitmap/992 "2023-11-24T16:54:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bugan11](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/b/c5a1d2/32.png) [@bugan11](https://forum.castle-engine.io/u/bugan11)\
**Post date:** [November 24, 2023, 4:54pm UTC](https://forum.castle-engine.io/t/drawing-tbitmap/992/1 "2023-11-24T16:54:54Z")

</div>

Hello, is there any way to draw TBitmap type from Delphi in CGE? I know there is TDrawableImage which takes TCastleImage, where currently I am doing conversion, but manually pixel by pixel and thats quite slow. I cant load the picture from disk, as its created during runtime in memory. So is there any method to draw default bitmap type in CGE, or any quicker conversion variant (as I have to manually update it on change multiple times during runtime, meaning to undergo slow conversion again)? I would try to copy internal memory structure to RawPixels with bitmap scanline, but as pixels in TRGBAlphaImage are of type TVector4Byte, internal memory representation would not be compatible either way I guess. Thanks.

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [November 27, 2023, 3:57pm UTC](https://forum.castle-engine.io/t/drawing-tbitmap/992/2 "2023-11-27T15:57:41Z")

</div>

We don’t support directly using Delphi’s `TBitmap`. As you mention, we have our own `TDrawableImage` (which can be drawn) and `TCastleImage` (which has `RawPixels` and can be used as initial contents of `TDrawableImage`).

Indeed the way to go is to copy over between `TBitmap.ScanLine` and our `RawPixels`, and account for differences. You will likely need to swap RGB\<-\>BGR indeed. Some code in CGE already does this when converting with other libraries, like `src/images/castleimages_vcl_imaging.inc` (uses Delphi `TPngImage`) or `src/images/castleimages_vampyre_imaging.inc` (loads using Vampyre Imaging; I see we actually use `SwapChannels` from Vampyre in this case).

So, we don’t have a better approach, but you can manually copy (and eventually RGB\<-\>BGR swap) and it may be fast enough for some purposes.

An alternative approach may be to not use Delphi’s `TBitmap` and do 100% image drawing using CGE 🙂 I know it depends on the situation though.

---

<div class="post-metadata">

**Author:** ![bugan11](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/b/c5a1d2/32.png) [@bugan11](https://forum.castle-engine.io/u/bugan11)\
**Post date:** [November 28, 2023, 2:43pm UTC](https://forum.castle-engine.io/t/drawing-tbitmap/992/3 "2023-11-28T14:43:09Z")

</div>

Well as I do extend current application with CGE as one of the options to display, I need to rely on using constructs I get, in this case I do get TBitmap instance and that I need to draw. But I used LoadEncodedImage method where I put bitmap into stream and it works a bit faster so for now it will do, thanks.
