在图像上写RTF [英] write RTF on an image

查看:79
本文介绍了在图像上写RTF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在图像上编写RTF ...我查看了这篇文章 - [C#] RTF文本到位图图像?任何简单的方法? 这是我正在寻找的绝对解决方案,但当我尝试调用

g.DrawRtfText(rtfStr, new RectangleF(0,0,bmp.Width,bmp.Height),1f);



在将文本写入图像文件时修剪文本。



无论如何都要将完整的文字放入此图片中。这是代码,它可能有助于了解我想要实现的目标。



string rtfStr =((System.Windows.Forms.RichTextBox)(printingEditor))。Rtf;

位图bmp = new Bitmap(1400,1800);



图形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);

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);

推荐答案

例如,你可以做相反的事情:首先,创建一个更大的位图,以适应RTF内容。创建图像后,您可以按照自己的方式重新对其进行重新采样。为此,创建一个所需大小的新图像,并从该位图获取类 System.Drawing.Graphics 的实例,以便在其上绘制:

http://msdn.microsoft.com/en-us/library /system.drawing.graphics.fromimage.aspx [ ^ ]。



(我很确定这项技术在您使用的文章中得到了证明代码。)



完成后,使用其中一种方法 System.Drawing在目标位图上绘制第一个位图并进行适当的缩放.Graphics.DrawImage



可能这不是唯一的方法,因为你可以在第一时间扩展RTF内容,但是我描述的方法是最普遍的。它也用于抗锯齿图形(如果这部分不清楚,我可以解释)。



你也可以问你的向文章作者提问(顺便提一下,下次提供您所引用的所有资料的链接)。为此,请加载文章的页面,找到评论和讨论部分,然后点击添加评论或问题以发布您的问题。该文章的作者将收到通知和更改以回答您。



-SA
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


这篇关于在图像上写RTF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆