How to embed bitmaps in an RTF file using VB? 
Author Message
 How to embed bitmaps in an RTF file using VB?

The easiest way is to simply copy your Image to the Clipboard and then
paste it into an RTF control containing your document. Limited coding,
no mess, no fuss.

If you want to do this strictly via code then you'll have to spend
some/a lot of time with the Rich Edit spec. I do have code I created to
embed Metafiles within an RTF file. You only need  small change to allow
for Bitmap data. It's in an Access MDB here:
http://www.*-*-*.com/

It's been a while since I wrote this but if I remember correctly, with
the exception of Enhanced Metafiles, you will have to convert the binary
pixel data of your image to string Hex data with code like:

' OK we are now done creating and modifying the records of our
' Metafile. Now we need to prepare this data for encoding
' into the RTF file.

' Emit Binary Data as HEX string values
' This will double the size of the Binary Data.
' Each Byte will require 2 Hex string characters.
ReDim bArrayHex((UBound(bArray) * 2) + 1)
x = 0
' Loop through Our Metafile Bytes
For y = 0 To (UBound(bArray))
    ' Grab a Byte and convert it to Hex
    strTemp2 = Hex(bArray(y))
    'if it is only one character put a "0" in front
    If Len(strTemp2) = 1 Then strTemp2 = "0" & strTemp2
    ' Store the individual Ascii chars back into an Array
    bArrayHex(x) = Asc(Mid(strTemp2, 1))
    bArrayHex(x + 1) = Asc(Mid(strTemp2, 2))
    x = x + 2
Next

' Copy the Metafile Data that has been converted to
' Hex strings our to our RTF file.
Put FnumTemp, , bArrayHex

' Write the Closing Brace for this Picture
Put FnumTemp, , strClosingBrace

One of the advantages of using EMF is that you can embed the EMF
directly without having to convert to Hex and storing it as a string.

--

HTH
Stephen Lebans
http://www.*-*-*.com/
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Quote:
> I have to embed bitmaps into an RTF file using Visual
> Basic. When you Insert an image into an rtf file using
> Word Pad and view the source of the rtf file, it embeds
> the image by translating the bitmap into Hex (??). I am
> trying to achieve the same using VB. Using GetDIBits or
> GetBitmapBits I can get a reference to the bitmap but how
> do I then process these bits so that I can embed the whole
> bitmap into the RTF file.
> Please help me out.



Sun, 08 May 2005 11:26:58 GMT  
 How to embed bitmaps in an RTF file using VB?
I was using the same approach, but unfortunately it
doesn't work for Bitmaps. Any further ideas?? Thanks for
your help
-J
Quote:
>-----Original Message-----
>The easiest way is to simply copy your Image to the
Clipboard and then
>paste it into an RTF control containing your document.
Limited coding,
>no mess, no fuss.

>If you want to do this strictly via code then you'll have
to spend
>some/a lot of time with the Rich Edit spec. I do have
code I created to
>embed Metafiles within an RTF file. You only need  small
change to allow
>for Bitmap data. It's in an Access MDB here:
>http://www.lebans.com/ReportUtilities.htm

>It's been a while since I wrote this but if I remember
correctly, with
>the exception of Enhanced Metafiles, you will have to
convert the binary
>pixel data of your image to string Hex data with code
like:

>' OK we are now done creating and modifying the records
of our
>' Metafile. Now we need to prepare this data for encoding
>' into the RTF file.

>' Emit Binary Data as HEX string values
>' This will double the size of the Binary Data.
>' Each Byte will require 2 Hex string characters.
>ReDim bArrayHex((UBound(bArray) * 2) + 1)
>x = 0
>' Loop through Our Metafile Bytes
>For y = 0 To (UBound(bArray))
>    ' Grab a Byte and convert it to Hex
>    strTemp2 = Hex(bArray(y))
>    'if it is only one character put a "0" in front
>    If Len(strTemp2) = 1 Then strTemp2 = "0" & strTemp2
>    ' Store the individual Ascii chars back into an Array
>    bArrayHex(x) = Asc(Mid(strTemp2, 1))
>    bArrayHex(x + 1) = Asc(Mid(strTemp2, 2))
>    x = x + 2
>Next

>' Copy the Metafile Data that has been converted to
>' Hex strings our to our RTF file.
>Put FnumTemp, , bArrayHex

>' Write the Closing Brace for this Picture
>Put FnumTemp, , strClosingBrace

>One of the advantages of using EMF is that you can embed
the EMF
>directly without having to convert to Hex and storing it
as a string.

>--

>HTH
>Stephen Lebans
>http://www.lebans.com
>Access Code, Tips and Tricks
>Please respond only to the newsgroups so everyone can
benefit.



>> I have to embed bitmaps into an RTF file using Visual
>> Basic. When you Insert an image into an rtf file using
>> Word Pad and view the source of the rtf file, it embeds
>> the image by translating the bitmap into Hex (??). I am
>> trying to achieve the same using VB. Using GetDIBits or
>> GetBitmapBits I can get a reference to the bitmap but
how
>> do I then process these bits so that I can embed the
whole
>> bitmap into the RTF file.
>> Please help me out.

>.



Mon, 09 May 2005 02:07:29 GMT  
 How to embed bitmaps in an RTF file using VB?

Quote:
> I was using the same approach, but unfortunately it
> doesn't work for Bitmaps. Any further ideas??

I only had a quick peek at an RTF in a hex editor, but it looks like the
bitmap is being stored within an EMF (WMF?) and that is embedded in the
file?  Have a look for an RTF spec for confirmation on this though.
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Mon, 09 May 2005 02:33:38 GMT  
 How to embed bitmaps in an RTF file using VB?
The methodology does work with Bitmaps because when I started out I
embedded Bitmaps before I moved to Metafiles. Sorry, I don't have that
code anymore as that was revision 8 or 9 out of 50 and I had deleted
everything under revision10.

For now, to get you going, simply Blit your Bitmap onto a Metafile DC
and then use my code as is to embedd the EMF.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Quote:
> I was using the same approach, but unfortunately it
> doesn't work for Bitmaps. Any further ideas?? Thanks for
> your help
> -J
> >-----Original Message-----
> >The easiest way is to simply copy your Image to the
> Clipboard and then
> >paste it into an RTF control containing your document.
> Limited coding,
> >no mess, no fuss.

> >If you want to do this strictly via code then you'll have
> to spend
> >some/a lot of time with the Rich Edit spec. I do have
> code I created to
> >embed Metafiles within an RTF file. You only need  small
> change to allow
> >for Bitmap data. It's in an Access MDB here:
> >http://www.lebans.com/ReportUtilities.htm

> >It's been a while since I wrote this but if I remember
> correctly, with
> >the exception of Enhanced Metafiles, you will have to
> convert the binary
> >pixel data of your image to string Hex data with code
> like:

> >' OK we are now done creating and modifying the records
> of our
> >' Metafile. Now we need to prepare this data for encoding
> >' into the RTF file.

> >' Emit Binary Data as HEX string values
> >' This will double the size of the Binary Data.
> >' Each Byte will require 2 Hex string characters.
> >ReDim bArrayHex((UBound(bArray) * 2) + 1)
> >x = 0
> >' Loop through Our Metafile Bytes
> >For y = 0 To (UBound(bArray))
> >    ' Grab a Byte and convert it to Hex
> >    strTemp2 = Hex(bArray(y))
> >    'if it is only one character put a "0" in front
> >    If Len(strTemp2) = 1 Then strTemp2 = "0" & strTemp2
> >    ' Store the individual Ascii chars back into an Array
> >    bArrayHex(x) = Asc(Mid(strTemp2, 1))
> >    bArrayHex(x + 1) = Asc(Mid(strTemp2, 2))
> >    x = x + 2
> >Next

> >' Copy the Metafile Data that has been converted to
> >' Hex strings our to our RTF file.
> >Put FnumTemp, , bArrayHex

> >' Write the Closing Brace for this Picture
> >Put FnumTemp, , strClosingBrace

> >One of the advantages of using EMF is that you can embed
> the EMF
> >directly without having to convert to Hex and storing it
> as a string.

> >--

> >HTH
> >Stephen Lebans
> >http://www.lebans.com
> >Access Code, Tips and Tricks
> >Please respond only to the newsgroups so everyone can
> benefit.



> >> I have to embed bitmaps into an RTF file using Visual
> >> Basic. When you Insert an image into an rtf file using
> >> Word Pad and view the source of the rtf file, it embeds
> >> the image by translating the bitmap into Hex (??). I am
> >> trying to achieve the same using VB. Using GetDIBits or
> >> GetBitmapBits I can get a reference to the bitmap but
> how
> >> do I then process these bits so that I can embed the
> whole
> >> bitmap into the RTF file.
> >> Please help me out.

> >.



Tue, 10 May 2005 11:10:37 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Displaying Embedded Bitmaps using Bound Controls

2. Rich Text File (.RTF) -Can't copy multiple .rtf files (VB 6.0 Enterprise)

3. Unreadable html, RTF using embedded objects

4. RTF OCX unable to read RTF fiels with embedded images

5. Creating/Embedding Pictures/Images in RTF files

6. RTF File Control and embedded images

7. RTF Files (.rtf) inside a Resource file (.res)?

8. Rich Text File (.RTF) -Can't copy multiple .rtf files

9. Amount of ram used by embedded VB program using inclueded db engine

10. Embedded Bitmaps and Namespace Referencing

11. Embedding bitmaps in CRW 7.0

12. Adding .RTF .WRI .DOC files to VB programs with those files tagging along

 

 
Powered by phpBB® Forum Software