[Closed] Writing text in bitmap
Hi!
Simple question, what is the easiest way to write text in a bitmap at a given position and controling the font size? .NET , Post? Any example will be appreciated.
Thanks
If you have access to Python you can use the PIL Imaging library. It’s really easy to learn, tons of tutorials / scripts etc. I’m loving it so far. It’s also compatible with newer versions of 3ds Max.
You could use the SVG engine that comes with the vector texturmap
See the MXS example at the bottom of this page, titled “Using SVG To Render Text To Bitmap”
http://help.autodesk.com/view/3DSMAX/2015/ENU/?guid=__files_GUID_3EF5C2D1_992C_4F29_8543_72D61F2870D1_htm
this is how I do it
fn DotNetFont fontname size style =
(
FontStyle = dotnetclass "System.Drawing.FontStyle";
fs = case style of
(
#regular: FontStyle.regular;
#bold: FontStyle.bold;
#italic: dotnetclass.italic;
#underline: FontStyle.underline;
#strikeout: FontStyle.strikeout;
default: FontStyle.regular;
)
dotnetobject "System.Drawing.Font" fontname size fs;
)
fn DotNetPasteBitmap src_bitmap dest_bitmap dest_rect =
(
gr = (dotnetclass "System.Drawing.Graphics").FromImage dest_bitmap;
gr.DrawImage src_bitmap dest_rect;
gr.Dispose();
)
fn DotNetOffsetRect pos width height =
( dotnetobject "System.Drawing.Rectangle" (DotNetPoint pos) (DotNetSize width height); )
fn DotNetColor mc = ((dotnetclass "System.Drawing.Color").FromArgb mc.r mc.g mc.b; )
fn DotNetTextToBitmap txt font col =
(
-- create temp context so we can measure the text width
temp_bm = dotnetobject "System.Drawing.Bitmap" 1 1
temp_gr = (dotnetclass "System.Drawing.Graphics").FromImage temp_bm
sz = (temp_gr.MeasureString txt font).ToSize();
temp_bm.dispose();
temp_gr.dispose();
-- create the actual draw context
bm = dotnetobject "System.Drawing.Bitmap" sz.width (font.GetHeight())
gr = (dotnetclass "System.Drawing.Graphics").FromImage bm
-- set render to best quality
gr.PixelOffsetMode = gr.PixelOffsetMode.HighQuality
gr.TextRenderingHint = gr.TextRenderingHint.AntiAliasGridFit
-- make the background transparent
gr.Clear (dotnetclass "System.Drawing.Color").transparent
-- render the string to the bitmap
gr.DrawString txt font (dotnetobject "System.Drawing.SolidBrush" col) 0 0
-- release the drawing context
gr.Dispose()
-- return the bitmap
bm
)
then call something like this where dest_bm is also a dot net bitmap/image
darkbluegray = color 24 24 32;
font = DotNetFont "Comic Sans Ms" 11 #bold;
text_bm = DotNetTextToBitmap "Hello World" font (DotNetColor darkbluegray) ;
DotNetPasteBitmap text_bm dest_bm (DotNetOffsetRect pos width height);
text_bm.dispose();
you can also render directly to the image with a few changes to the above