Create BaseBitmap() from Text?
Is it possible to create bitmap from text?
Currently, I use separate thumbnail/image files to be use as bitmap but they are relatively simple
that perhaps I can do them at run time in C4D.
You can see what I am after in this image:
The use case for this is a toggle button for HIDE/UNHIDE visibility control. The Green means hide and the Red means unhide. I already have the toggle functionality implemented, its only the BaseBitmap() from Text portion.
m_adam last edited by
Or you can Create a GeUserArea that will display your BaseBitmap GeUserArea.DrawBitmap and then call GeUserArea.DrawText
The use of GeUserArea is preferred since it's faster than using a GeClipMap. But you can't retrieve a BaseBitmap from your GeUserArea drawing result, so it's up to you do decide which one fits the best for your use case.
Thanks for the response. I was able to draw a text with a colored background.
Just hit a snag on this portion.
I'm assuming the font description is the font name and font type.
How do I set it to
m_adam last edited by
This is a bit tricky since Font are not so well organized.
So the best way I found is
def GetSegoeUiBoldFont(): bcFonts = c4d.bitmaps.GeClipMap.EnumerateFonts(c4d.GE_CM_FONTSORT_HIERARCHICAL) for familyId, familyBc in bcFonts: for fontDescriptionId, fontDescription in familyBc: if fontDescription == "SegoeUI-Bold": return fontDescription
And if you want another font, simply print the content of fontDescription and see which one may fit the best for you.
Thanks for the response. For some reason, the return value is not accepted by the
SetFont. It does not error out. It just uses the default font.
In addition, how were you able to determine that the
is for the font name? I can't seem to see such reference in the documentation.
You can check the working code here:
import c4d from c4d import gui # Welcome to the world of Python def GetSegoeUiBoldFont(): bcFonts = c4d.bitmaps.GeClipMap.EnumerateFonts(c4d.GE_CM_FONTSORT_HIERARCHICAL) for familyId, familyBc in bcFonts: for fontDescriptionId, fontDescription in familyBc: if fontDescription == "SegoeUI-Bold": return fontDescription print fontDescription def main(): w = 50 h = 50 image_with_text = c4d.bitmaps.GeClipMap() image_with_text.Init(w=w,h=h,bits=32) image_with_text.BeginDraw() image_with_text.SetColor(125,255,255) image_with_text.FillRect(x1=0,y1=0,x2=50,y2=50) image_with_text.SetColor(0,0,0) font_bc = GetSegoeUiBoldFont() print font_bc font_size = 15 image_with_text.SetFont(font_bc,font_size) image_with_text.TextAt(x=10,y=15,txt='head') image_with_text.EndDraw() bmp = image_with_text.GetBitmap() c4d.bitmaps.ShowBitmap(bmp) # Execute main() if __name__=='__main__': main()