Solved

Converting Image to RTF picture

Posted on 2002-04-22
16
1,506 Views
Last Modified: 2008-02-26
I want to create a function in an ActiveX dll that when passed a JPEG file, will convert the file to the RTF formatted picture (starting with "{\pict").

I want to be able to append truly embedded images to an rtf file.

I have been able to do this with a visual interfaced VB exe by loading a picture in the picture control and then copying the image to the clipboard and pasting to a richtextcontrol box .  This however is not a feasible or appropriate solution for an ActiveX dll.
0
Comment
Question by:wengier
  • 4
  • 3
  • 2
  • +4
16 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6961726
I'd pay BIG money for this code too!!  (...listening...)
0
 
LVL 5

Expert Comment

by:ianouii
ID: 6962337
learning...
0
 
LVL 3

Expert Comment

by:baldrick
ID: 6962348
Interesting... (I didn't realise RTFs could do this). I might be wondering down the completely wrong path here, but I tried the following...

1. Right clicked EE logo & saved it locally in GIF & BMP formats.

2. Copied EE logo onto clipboard, pasted it into WordPad & saved it into an RTF file.

3. A quick once over the RTF file in Notepad compared to the graphics formats under a hex editor reveals that the image data is held as an ASCII image of uncompressed binary data, very similar to a BMP file. It seems to be able to handle 8 and 24 bits-per-pixel images.

The "\wmetafile8" tag gives me the hunch that it's actually an ASCII windows metafile of a raster graphic. I seem to recall that there's several functions in the Win32 API for reading & writing WMF files: the following sites might give some clues...

http://www.faqs.org/faqs/graphics/fileformats-faq/part3/section-159.html

http://www.companionsoftware.com/PR/WMRC/WindowsMetafileFaq.html

Petzold's "Programming Windows" has a very accessible intro to these although all examples are given in C.

Even if the API has support for writing WMFs directly as ASCII values, you'll still have the little problem of decoding a JPEG file into an uncompressed bitmap. This is tough, I've found a C implementation at :

http://support.intel.com/support/performancetools/libraries/ijl/decode.htm

It might be simpler if you start by writing your control to handle .BMP and .PCX decoders first, they're a lot simpler internally. Alternatively there may be freeware ActiveX DLLs around which will do this for you.

Hope this is of some help.
0
 
LVL 1

Expert Comment

by:manno
ID: 6962426
I think you CAN have a form in your ActiveX DLL; just don't show it.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6963065
Well, to this time i got this (just an example).
{\pict\wmetafile8\picw3968\pich1428\picwgoal2250\pichgoal810
they means (i think)....
{\pict\wmetafile8: always the same, start of image
\picw3968: width of image -1 in HIMETRIC units.
\pich1428: height of image -1 in HIMETRIC units.
\picwgoal2250: ? (maybe boundaries Width)
\pichgoal810:? (maybe boundaries Height)

After that comes "real" image in hex?
It appears like between hex values rtf adds some 0 ones, i am checking right know....
What i am tring to do is load image in binary format and append it to rtf in same way.
To get HIMETRIC values i am using an StdPicture object.
Keep rolling....
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6963070
Good luck Richie...I played with this a few months ago and could never find out how to read the jpeg file's contents and convert them into the format they are stored in in the RTF fiel (I dont think its a straight read...more than likely, along the lines of what baldrick mentions above)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6963117
This is my analisis:
follow is a representation (in hex ) of first bytes of some image:

474946383961960036'00F70000000000FFFFFF004D9CFFD710F7F9FC00B8D8A1BDDBAEC6......

This is the same image but inside rtf document (some lines only):

0100090000038114000002002a1200000000050000000b0200000000050000000c029405800f05
0200'00f7000003000100000000ffffff00004d9c00ffd71.....

As you could see, things starts to make sense at
00F70000000000FFFFFF004D9C...............

You could see marks where things start to match....
0
 
LVL 1

Expert Comment

by:manno
ID: 6963391
Following on from my previous comment. You said up front:

[I have been able to do this with a visual interfaced VB exe by loading a picture in the picture control
and then copying the image to the clipboard and pasting to a richtextcontrol box .  This however is
not a feasible or appropriate solution for an ActiveX dll.]

Why is this not feasible? (Hide the form). Or appropriate?

Regards

Steve Mann
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Expert Comment

by:baldrick
ID: 6963962
Richie_Simonetti,
To make matters even worse the contents of the RTF will vary depending on colour depth. For example, an 8 bit-per-pixel bitmap can contain up to 256 colours, so it's most likely that raw palette information will also be tacked on at the end. In the quick (8 bpp) image test I last tried, the first 44 or so bytes of binary were unintelligible but were immediately followed by equivalent BMP data. I imagine those first 44 bytes are headers for width, height, colour depth, encoding method etc., and I still strongly suspect that Windows metafiles have something to do with it. If it *is* feasible to embed an undisplayed form in an ActiveX DLL (I can't imagine why not) then plonking a rich-textbox & picturebox in it for the conversions would dramatically simplify things.

Best of luck
0
 

Author Comment

by:wengier
ID: 6997811
The reason I said it was not feasible is that the Active X dll would be called from ASP.  The script could possible be called multiple times a second, by different users.  I beleive that the clipboard is a shared resource.  As such, it may be possible that copying and pasting into the clipboard by different instances of the dll could cause incorrect pictures to be pasted.  I might be very off base here. If so, then my initial solution may work.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7660691
Hi wengier,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: baldrick and manno

    *** clipboard (technique revisited by manno) will work:  OpenClipboard locks it, so just check to see if it is locked and sleep a while if so.
    *** baldrick clearly put some effort in here and desrves some vredit
    *** I am open to suggestions, also

wengier, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 500 total points
ID: 7662148
Well the clipboard technique was mentioned to be inappropriate because this is going to be a COM component used from ASP pages.  There is that slight chance that two people are requesting this document at the same time, but have two alternate images, so there could be a:

User1 pastes image to Clipboard
User2 pastes image to Clipboard
User1 embeds image from Clipboard to Richtextbox
User2 embeds image from Clipboard to Richtextbox

Thus, both users get User2's image.


I have written COM objects doing the exact same thing for use in ASP pages and have always opted for:

Call Richtextbox.OLEObjects.Add(, , strFile).DoVerb(-3)


but I am pretty sure you are limited to bitmaps there.  It would have been nice to see someone figure out what exactly goes on internally with the richtextbox and images.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7664442
Thanks for the feedback AzraSound.
My thought was that once User1 had opened the clipboard, then when User2 tried to open it, the OpenClipboard call would fail.  So User2 could simply sleep for 100ms, then try again.  

I agree that the whole clipboard thing smells of kludge, but it seems like the only suggestion that is close to a working solution.  A very little research ought to resolve this:  If you can paste from the clipboard, you should be able to create the same object as a file (et al.) and insert it directly.  The alternative ideas of cracking the RTF coding is also viable, but looks like more work.  If this were a current question (it is 8 months old) and if it were posed in the C++ TA, and if it were worth 500 points, I'd be on it like stink on uhhh, a skunk.

-- Dan
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7672028
[Un]fortunately, as you know, VB hides a lot of the grunt work regarding much Windows programming, including the clipboard.  In VB, there is no opening of the clipboard, closing it, etc.  You have a clipboard object and just say copy, paste, etc.  VB automatically does the opening and closing for you in that single function call.  Agreed, though, that this thread has probably received all the input it will get from those who have participated.
0
 

Author Comment

by:wengier
ID: 7672212
I have awarded the points to AzraSound because this is actually the solution that I came up with.  It is not perfect, but it works.  I have a component that I use to convert the jpeg file to a bmp file and then use Richtextbox.OLEObjects.Add to get the equivalent rtf information.  I parse out the actual image portion of the resultant rtf file in order to use this image in another rtf file.

Thanks to everyone for their input on this question.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7675296
Thanks wengler.  Keeping track of your open questions, and closing them to award points is a very good thing!

-- Dan
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now