rtf格式文件转换为bmp格式文件

QIHONGWEI_2000_0 2009-04-16 04:06:14
c#如何将rtf格式的文件转换成bmp格式文件
...全文
427 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
stone21cn 2011-11-14
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 wartim 的回复:]
网上有现成的代码,我整理了一下

C# code
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Wind……
[/Quote]
这个居然有{"GDI+ 中发生一般性错误。"}的错误,怎么解决?
wartim 2009-04-25
  • 打赏
  • 举报
回复
网上有现成的代码,我整理了一下
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication39
{
public partial class Form1 : Form
{
[DllImport("USER32.dll")]
private static extern Int32 SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);
private const int WM_USER = 0x400;
private const int EM_FORMATRANGE = WM_USER + 57;

[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}

[StructLayout(LayoutKind.Sequential)]
private struct CHARRANGE
{
public int cpMin;
public int cpMax;
}

[StructLayout(LayoutKind.Sequential)]
private struct FORMATRANGE
{
public IntPtr hdc;
public IntPtr hdcTarget;
public RECT rc;
public RECT rcPage;
public CHARRANGE chrg;
}

private const double inch = 14.4;
private Rectangle contentRectangle;

public Form1()
{
InitializeComponent();

button1.Click += new EventHandler(SaveAsJpegButton_Click);
richTextBox1.ContentsResized += new ContentsResizedEventHandler(richTextBox1_ContentsResized);
}

private void SaveAsJpegButton_Click(object sender, EventArgs e)
{
RtbToBitmap(richTextBox1, contentRectangle, @"c:\rtb.jpg");
}

private void RtbToBitmap(RichTextBox rtb, Rectangle rectangle, string fileName)
{
Bitmap bmp = new Bitmap(rectangle.Width, rectangle.Height);
using (Graphics gr = Graphics.FromImage(bmp))
{
IntPtr hDC = gr.GetHdc();
FORMATRANGE fmtRange;
RECT rect;
int fromAPI;
rect.Top = 0; rect.Left = 0;
rect.Bottom = (int)(bmp.Height + (bmp.Height * (bmp.HorizontalResolution / 100)) * inch);
rect.Right = (int)(bmp.Width + (bmp.Width * (bmp.VerticalResolution / 100)) * inch);
fmtRange.chrg.cpMin = 0;
fmtRange.chrg.cpMax = -1;
fmtRange.hdc = hDC;
fmtRange.hdcTarget = hDC;
fmtRange.rc = rect;
fmtRange.rcPage = rect;
int wParam = 1;
IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
Marshal.StructureToPtr(fmtRange, lParam, false);
fromAPI = SendMessage(rtb.Handle, EM_FORMATRANGE, wParam, lParam);
Marshal.FreeCoTaskMem(lParam);
fromAPI = SendMessage(rtb.Handle, EM_FORMATRANGE, wParam, new IntPtr(0));
gr.ReleaseHdc(hDC);
}
bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();
}

private void richTextBox1_ContentsResized(object sender, ContentsResizedEventArgs e)
{
contentRectangle = e.NewRectangle;
}
}
}
weir55 2009-04-20
  • 打赏
  • 举报
回复
C# convert pdf to bmp
貌似在博客园看到过
你可以去找找看
我很懒 2009-04-20
  • 打赏
  • 举报
回复
去codeproject找吧!有现成的源码?有没有人知道"C# convert pdf to bmp"
qlzf11140820 2009-04-20
  • 打赏
  • 举报
回复
帮顶
QIHONGWEI_2000_0 2009-04-20
  • 打赏
  • 举报
回复
19楼的兄弟给个网址
linamong 2009-04-18
  • 打赏
  • 举报
回复
我觉得 截图可能可以

但是如果获取的是richtextbox的工作区域.
可能图片之外的空白区域也被截取保存了.

获取richtextbox应该简单,自己找找就找到了.

不过单独获取richtextbox里的图片区域我就不知道了.
QIHONGWEI_2000_0 2009-04-18
  • 打赏
  • 举报
回复
14楼的兄弟这好像是VC的,我是用的c#
zzxap 2009-04-18
  • 打赏
  • 举报
回复
先hWnd为RcihEdit的窗口句柄
HBITMAP CTextObj::CaptureWnd(HWND hWnd,LPRECT lpRect)
{
return hBitmap;
}

然后,
BOOL CDdbObj::SaveBmp(HBITMAP hBitmap, CString FileName)
{
return TRUE;
}
zzxap 2009-04-18
  • 打赏
  • 举报
回复
The ITextHost interface has methods that the windowless control calls to retrieve information about your window. For example, the text services object calls the TxGetDC method to retrieve a device context into which it can draw. The windowless control calls the TxNotify method to send notifications, such as the rich edit notification messages, to the text host. The text services object calls other ITextHost methods to request the text host to perform other window-related services. For example, the TxInvalidateRect method requests the text host to add a rectangle to the window's update region.

A standard rich edit control has a window procedure that processes system messages and messages from your application. You can use the control's window handle to send it messages for performing text editing and other operations. But a windowless rich edit control has no window procedure to receive and process messages. Instead, it provides an ITextServices interface. To send messages to a windowless rich edit control, call the TxSendMessage method. You can use this method to send any of the rich edit messages or to pass on other messages that affect the control, such as system messages for mouse or keyboard input.

You can also create the text services object as part of a COM-aggregated object. This makes it easy to aggregate the text services object with a windowless Component Object Model (COM) object.

http://codeproject.com/com/cominterfacehookingpart.asp?df=100&forumid=25002&fr=26
zzxap 2009-04-18
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/richedit/windowlessricheditcontrols.asp

This section contains information about the programming elements used with windowless rich edit controls. The Component Object Model (COM) defines a set of interfaces to support windowless objects. Windowless objects can enter the in-place active state without having their own window, but rather use the window of their container. Consequently, a windowless object uses fewer system resources and gives better performance through faster activation and deactivation. In addition, windowless objects can be nonrectangular and transparent.
sharp_future 2009-04-17
  • 打赏
  • 举报
回复
学习
QIHONGWEI_2000_0 2009-04-17
  • 打赏
  • 举报
回复
帮忙了
vrhero 2009-04-17
  • 打赏
  • 举报
回复
风马牛不相及的格式怎么能直接转...打印或截图...
QIHONGWEI_2000_0 2009-04-17
  • 打赏
  • 举报
回复
11楼的兄弟能说的详细一点吗
FlyBee 2009-04-17
  • 打赏
  • 举报
回复
虚拟打印机软件
wuyq11 2009-04-16
  • 打赏
  • 举报
回复
参考或用软件
txt_paul 2009-04-16
  • 打赏
  • 举报
回复
倾情一顶
麻子Mozart 2009-04-16
  • 打赏
  • 举报
回复
帮顶
QIHONGWEI_2000_0 2009-04-16
  • 打赏
  • 举报
回复
哪位高手,快快帮帮忙
加载更多回复(4)

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧