我想轉換一個位圖文件採用Delphi 2007圖像不顯示在MS Word從位圖將其轉換爲RTF後(但在寫字板顯示)
我用下面的代碼轉換到rtf。
function BitmapToRTF(pict: TBitmap): string;
var
bi, bb, rtf: string;
bis, bbs: Cardinal;
achar: ShortString;
hexpict: string;
I: Integer;
begin
GetDIBSizes(pict.Handle, bis, bbs);
SetLength(bi, bis);
SetLength(bb, bbs);
GetDIB(pict.Handle, pict.Palette, PChar(bi)^, PChar(bb)^);
rtf := '{\rtf1 {\pict\dibitmap0 ';
SetLength(hexpict, (Length(bb) + Length(bi)) * 2);
I := 2;
for bis := 1 to Length(bi) do
begin
achar := Format('%x', [Integer(bi[bis])]);
if Length(achar) = 1 then
achar := '0' + achar;
hexpict[I - 1] := achar[1];
hexpict[I] := achar[2];
Inc(I, 2);
end;
for bbs := 1 to Length(bb) do
begin
achar := Format('%x', [Integer(bb[bbs])]);
if Length(achar) = 1 then
achar := '0' + achar;
hexpict[I - 1] := achar[1];
hexpict[I] := achar[2];
Inc(I, 2);
end;
rtf := rtf + hexpict + ' }}';
Result := rtf;
end;
現在我的問題是我沒能在MS Word或查看器來查看圖像。
但我可以在word pad中查看圖像。
請建議我解決這個問題。
你的意思是說你將一個BMP文件轉換成一個嵌入BMP文件的RTF文件? – 2010-06-22 12:25:38
是的,我的意思是,嵌入一個bmp到RTF文件 – Bharat 2010-06-22 12:27:54
採取bmp文件,手動將其包含在Word中,將文檔保存爲rtf格式。查看保存的文件與您的文件的不同之處。嘗試通過刪除看起來多餘的命令來找出哪些是Word所必需的,以剝離rtf文件。但是這很麻煩,因爲不同的Word版本有不同的rtf版本。 – 2010-06-28 11:33:40