Convert any bitmap to an RTF (rich text) string

Share your advanced PureBasic knowledge/code with the community.
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Post by Blue »

srod wrote:Update : 18th Jan 2009.

Problems with Wordpad recognising rtf with an embedded EMF [...]

@Blue : this should fix your problem.
I hadn't tried the result of the original code with MSWord, not realizing that there would be a difference with Wordpad.

I'll use the updated code, but, before anything else, i'll try the old test.rtf with MSWord. Just to see.

Many thanks for the attention, srod. Much appreciated. I was beginning to feel embarassed, seeing how everybody else was getting results :oops:


-----------------------------------------------------------
Feedback:
Using the first version of your code, i could see, when opening the RTF with Word, that the pic had indeed been embedded.
Plus it also worked with WordPad after re-saving the file from within Word.

-----------------------------------------------------------
Feedback 2:
just tested the updated code. Impeccable.
And you weren't kidding when you announced speed improvement: from snail pace to Mach-1 in one version change. Very impressive. :shock:
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Yes, rtf 'readers' (of which the RichEdit control is one) are free to ignore data streams that they cannot be bothered to support. It would seem that EnhancedMetaFiles and png files are examples of such streams that the basic RichEdit control (and thus WordPad) simply ignore. Perhaps the latest versions of the RichEdit control rectify this, but I haven't tested?

In the case you outlined when saving the rtf from MS Word and then viewing in WordPad, MS Word is kind enough to embed images in multiple formats; one of which is a basic MetaFile (not an enhanced one) which most readers are fine with.
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re:

Post by PB »

I noticed I can drag-and-drop a zip file into a WordPad document.
So, is there a way to maybe embed a zip file into a WordPad doc
like you've done with images? Or embed any type of binary file?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Convert any bitmap to an RTF (rich text) string

Post by srod »

Yes you can do it with editor gadgets (if that is what you are after) using, for example, my OLE 'images in editor gadgets' utility. It does require some alterations, however, following adjustments made by Nico. The code is a real mess now.

I can e-mail it to you if you want it?
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Convert any bitmap to an RTF (rich text) string

Post by PB »

I was hoping to use it to create a standalone RTF document,
like this bmp2rtf does, rather than just into an EditorGadget.
If it can, then yeah, I'll PM you for it. Thanks!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Convert any bitmap to an RTF (rich text) string

Post by srod »

Sorry I misunderstood. I was referring to an ability to embed any binary file into an editor gadget through drag and drop as opposed to creating an rtf file in which a zip file is embedded etc.

What you are after would surely be possible, but you would have to study the rtf specs to see how to embed such a file. The rtf header would be the all important factor.
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Convert any bitmap to an RTF (rich text) string

Post by PB »

No worries. I'm going to embed 2 different (but small) binaries to
two WordPad docs and then study the results with a hex editor. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Convert any bitmap to an RTF (rich text) string

Post by srod »

You don't need a hex editor. rtf is a 7-bit Ascii encoding. Just load the rtf file into notepad.
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Convert any bitmap to an RTF (rich text) string

Post by PB »

So I can create a RTF doc using CreateFile and WriteString? :shock:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Convert any bitmap to an RTF (rich text) string

Post by srod »

That's what I do in my code in the first post of this thread.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Convert any bitmap to an RTF (rich text) string

Post by srod »

http://latex2rtf.sourceforge.net/RTF-Spec-1.0.txt

Scroll down to the OBJECTS section.
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Convert any bitmap to an RTF (rich text) string

Post by PB »

> That's what I do in my code in the first post of this thread

:oops: I didn't look at your code too deeply (just skimmed it).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Convert any bitmap to an RTF (rich text) string

Post by ts-soft »

Is there a way to add alpha-support?

Greetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Zach
Addict
Addict
Posts: 1675
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Convert any bitmap to an RTF (rich text) string

Post by Zach »

I don't think you'll get an answer, you necro'd a 1 year old thread and s-rod is gone now I believe :idea:
Post Reply