void __fastcall TMainForm::DrawTextOnLayer(const int Index, const String Text) { int LayerIndex = MainDataModule->ImageList1->Destination->Items[Index]->Layers->Count - 1; if(LayerIndex >= 0) { TLayer * Layer = MainDataModule->ImageList1->Destination->Items[Index]->Layers->Items[LayerIndex]; String SourceName = Layer->Name; TSize Size; TCustomBitmapItem * Item; // Create a new source image if earlier its was not if(!MainDataModule->ImageList1->BitmapItemByName(SourceName, Item, Size)) { Size.cx = Layer->SourceRect->Rect.Width(); Size.cy = Layer->SourceRect->Rect.Height(); TCustomSourceItem * NewSource = MainDataModule->ImageList1->Source->Add(); NewSource->Name = SourceName; Item = NewSource->MultiResBitmap->ItemByScale(1, false, true); if(Item == NULL) { Item = NewSource->MultiResBitmap->Add(); } Item->Bitmap->SetSize(Size.cx, Size.cy); } // Output some text if(Item != NULL) { Item->Bitmap->Clear(TAlphaColor(0x0)); TCanvas * canvas = Item->Bitmap->Canvas; if(canvas->BeginScene()) { __try { canvas->Font->Size = 15; canvas->Fill->Color = TAlphaColor(TAlphaColorRec::Red); canvas->Fill->Kind = TBrushKind::Solid; canvas->FillText(TRectF(1, 0, Size.cx - 1, Size.cy / 2), Text, false, 1, TFillTextFlags(), TTextAlign::Center, TTextAlign::Center); } __finally { canvas->EndScene(); } }