Gilbert Posted November 14, 2008 Posted November 14, 2008 Hello! I have a question about a plugin I am currently writing (in CodeLab). Is there a way to render text to an image? Like: I want to write "50" at x 200px and y 300px. I have a color bar (like in a FEM-Software) and want to lable it now from top to bottom █ 1.0 █ 0.75 █ 0.5 █ 0.25 █ 0.0 Thanks a lot! Gilbert. Quote
BoltBait Posted November 14, 2008 Posted November 14, 2008 There is an example on this page: http://www.boltbait.com/pdn/codelab/hel ... ments.html // Author: Ego Eram Reputo #region UICode FontFamily Amount1 = new FontFamily("Arial"); // Font #endregion void Render(Surface dst, Surface src, Rectangle rect) { Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); ColorBgra PC = (ColorBgra)EnvironmentParameters.PrimaryColor; // Reset the destination canvas for (int y = rect.Top; y { for (int x = rect.Left; x { dst[x,y] = src[x,y]; } } // Create a brush and graphics surface to write on SolidBrush Brush1=new SolidBrush( Color.FromArgb(PC.A,PC.R,PC.G,PC.); Graphics g = new RenderArgs(dst).Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.Clip = new Region(rect); // Create a font from user selection Font SelectedFont=new Font(Amount1.Name, 16); // Write our text to the canvas g.DrawString("Paint.NET Rocks!", SelectedFont, Brush1, selection.Left, selection.Top); } Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
Ego Eram Reputo Posted November 16, 2008 Posted November 16, 2008 If spacing is critical I'd recommend hard coding the font and size, but you'd need therefore to make the font a generic one so that you don't have to worry about it not being found on the users machine. Google "web safe fonts" for a list :wink: The location of the text is set by the last two variables in the g.DrawString call, selection.Top and selection.Left in the above example. Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker
Gilbert Posted November 17, 2008 Author Posted November 17, 2008 Nice!!! 8) Thank you very much! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.