Click here to Skip to main content
15,915,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to write RTF on an image... I checked out this article- [C#] RTF text to bitmap image? Any easy way around? and it was the absolute solution I was looking for but I cant figure out one thing when I try to call the
g.DrawRtfText(rtfStr, new RectangleF(0, 0, bmp.Width, bmp.Height), 1f);

It trims the text while writing it to image file.

Is there anyway to fit the complete text into this image.Here is the code, it might help to see what I am trying to achieve.

string rtfStr = ((System.Windows.Forms.RichTextBox)(printingEditor)).Rtf;
Bitmap bmp = new Bitmap(1400, 1800);

Graphics g = Graphics.FromImage(bmp);
g.DrawRtfText(rtfStr, new RectangleF(0, 0, bmp.Width, bmp.Height), 2f);

string file = Path.Combine(path1, id.ToString() + ".tif");
bmp.Save(file);
Posted

1 solution

You can do, for example, the opposite: first, create a bigger bitmap, to fit the RTF content. When the image is created, you can re-sample it down the way you want. For this purpose, create a new image of required size and obtain the instance of the class System.Drawing.Graphics from this bitmap, to draw on it:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx[^].

(I'm pretty sure this technique is demonstrated in the article you used of its source code.)

When, this is done, draw the first bitmap on a target bitmap with proper scaling using one of the methods System.Drawing.Graphics.DrawImage.

Probably, this is not the only method, as you could scale the RTF content in first place, but the method I described is the most universal. It is also used for anti-aliasing of graphics (if this part is unclear, I can explain).

You can also ask your questions to the author of the article (by the way, next time, provide a link to all the material you reference). To do so, load the page of the article, locate the section "Comments and Discussions" and hit "Add a Comment or Question" to post your question. The author of the article will get a notification and a change to answer you.

—SA
 
Share this answer
 
v2
Comments
koul.bhawna 3-May-13 6:12am    
Thank you for quick response.. I will post it to the Author with complete references.
Thanks!
Sergey Alexandrovich Kryukov 3-May-13 10:27am    
You are welcome. Will you accept this answer (green button)?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900