export RTF file > image problem

Just starting out? Need help? Post your questions and find answers here.
Loopingstar
User
User
Posts: 18
Joined: Tue Oct 01, 2013 12:57 pm

export RTF file > image problem

Post 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
Loopingstar
User
User
Posts: 18
Joined: Tue Oct 01, 2013 12:57 pm

Re: export RTF file > image problem

Post by Loopingstar »

anyone can help me please ?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: export RTF file > image problem

Post by IdeasVacuum »

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Loopingstar
User
User
Posts: 18
Joined: Tue Oct 01, 2013 12:57 pm

Re: export RTF file > image problem

Post 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.
- chris -
New User
New User
Posts: 9
Joined: Sun Jun 06, 2010 10:43 am

Re: export RTF file > image problem

Post 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  

Last edited by - chris - on Mon Oct 07, 2013 9:00 pm, edited 1 time in total.
PB v5.62 x86/x64
Windows 10 Pro
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: export RTF file > image problem

Post 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
Loopingstar
User
User
Posts: 18
Joined: Tue Oct 01, 2013 12:57 pm

Re: export RTF file > image problem

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: export RTF file > image problem

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply