Page 1 of 1
export RTF file > image problem
Posted: Thu Oct 03, 2013 10:31 pm
by Loopingstar
Hello,
i want to export a file in RTF format.
everything works except for images.
Code: Select all
WriteStringN(0, "\qc{\*\shppict{\pict{\*\picprop\jpegblip}", #PB_UTF8)
;Bin2Hex image here
WriteStringN(0, "}}\par\par", #PB_UTF8)
I have already experimented with existing images in HEX format and it works.
But my problem is that I need to transform images (png or jpeg) into hex (bin2hex), but I do not know how.
I need the image file is physically loaded, not from memory.
Thnx
Re: export RTF file > image problem
Posted: Sat Oct 05, 2013 3:38 pm
by Loopingstar
anyone can help me please ?
Re: export RTF file > image problem
Posted: Sun Oct 06, 2013 1:12 am
by IdeasVacuum
Re: export RTF file > image problem
Posted: Mon Oct 07, 2013 6:22 pm
by Loopingstar
i've already tested, but it don't work (output's blank string).
I don't know how to convert images JPEG/PNG to HEX.
Re: export RTF file > image problem
Posted: Mon Oct 07, 2013 7:26 pm
by - chris -
Code: Select all
If CreateFile(0, "image.rtf")
WriteStringN(0, "{\rtf1", #PB_UTF8)
WriteStringN(0, "\qc{\*\shppict{\pict{\*\picprop\jpegblip}", #PB_UTF8)
;Bin2Hex image here
For n = 0 To ?imageEnd - ?imageStart - 1
WriteString(0, RSet(Hex(PeekA(?imageStart + n)), 2, "0"), #PB_UTF8)
Next n
WriteStringN(0, "}}\par\par", #PB_UTF8)
WriteStringN(0, "}", #PB_UTF8)
CloseFile(0)
EndIf
End
DataSection
imageStart:
IncludeBinary "image.jpg"
imageEnd:
EndDataSection
Re: export RTF file > image problem
Posted: Mon Oct 07, 2013 8:09 pm
by Little John
- chris - wrote:Code: Select all
[...]
;Bin2Hex image here
For n = 0 To ?imageEnd - ?imageStart
WriteString(0, RSet(Hex(PeekA(?imageStart + n)), 2, "0"), #PB_UTF8)
Next n
[...]
DataSection
imageStart:
IncludeBinary "image.jpg"
imageEnd:
EndDataSection
I think it should be
Code: Select all
For n = 0 To ?imageEnd - ?imageStart - 1
Re: export RTF file > image problem
Posted: Mon Oct 07, 2013 8:10 pm
by Loopingstar
Wow Chris, thank you very much!
This code works very well and is very fast.
I just changed the code a bit, because I needed the image is loaded from disk and not oncluded in binary file:
Code: Select all
image = LoadImage(#PB_Any, "myImageFile.jpg")
If IsImage(image)
*mem = EncodeImage(image, #PB_ImagePlugin_JPEG)
WriteStringN(0, "\qc{\*\shppict{\pict{\*\picprop\jpegblip}", #PB_UTF8)
For n = 0 To MemorySize(*mem)
WriteString(0, RSet(Hex(PeekA(*mem + n)), 2, "0"), #PB_UTF8)
Next n
WriteStringN(0, "}}\par\par", #PB_UTF8)
EndIf
Re: export RTF file > image problem
Posted: Tue Oct 08, 2013 8:33 am
by IdeasVacuum
RTF is Microsoft's format but even they don't use it anymore - if you want to save Word compatible files, take a look at MS DOCX (XML) format.
http://en.wikipedia.org/wiki/Office_Open_XML