The image does not appear in the word ms after converting it from Bitmap to RTF (but appears in the text box)

I am trying to convert a raster file to rtf using Delphi 2007.

I used the code below to convert.

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; 

Now my problem: I could not view the image in MS Word or Viewer.

But I can view the image in the text panel.

Please suggest me to solve this problem.

+4
source share
3 answers

I think the problem is that the Word implementation for RTF rendering asks for more information than Wordpad (I think for security reasons - to avoid overflowing attacks -), but this is pure speculation, which I must admit.

Try to be precise when describing bitmap information: for example, if the bitmap is 32-bit, use \ wbmbitspixel32, put the width and height in your rtf encoding with \ picw and \ pich, etc. You may be lucky with this.

Here is an example:

http://www.scribd.com/doc/25967552/Rtf1-Ansi-Ansicpg1252-Uc2-Deff0-Deflang1033-Fonttbl-f0-Froman-Fcharset0-Fprq2-Panose-02020603050405020304-Times-New-Rswiss-1 Fchar

+4
source

How can you convert an image to a text file? RTF is RichtTextFormat, I think?

I would take bmp and put it with the Microsoft Word API into a document, and save the document was rtf.

Tobi

0
source

If you want to view the image in MS Word or Word Viewer, convert the image to an EMF file and paste it into the RTF tags. ( Note: here you cannot view the image in Wordpad)

 {\rtf1 {\pict\emfblif <emf source> }} 

If you want to view the image in Wordpad, convert the image to a bitmap and paste it into RTF tags.

 {\rtf1 {\pict\dibitmap0 <bitmap source> }} 

I do not know why this is happening.

0
source

Source: https://habr.com/ru/post/1313512/


All Articles