Store Image in WBT Script
Keywords: Store Binary Image Pic Graphic WinBatch WBT Script
Question:
Hi all, besides the obvious "why?" I was wondering if I could somehow create a gif image file from within Winbatch. I was able to binary read
a gif file and write the contents to a new file but I have no idea on how to convert the binary buffer to text/hex, store the data in a Winbatch
script and create the file whenever necessary.Is this possible?
Answer:
If you have the WinBatch + Compiler edition, you can include your gif image in the compiled EXE and extract it at will. This is the recommended method.
You must compile as a LARGE exe and use the OtherFiles button to attach your gif image file. In your script, the command to extract the attached file is simply:
ExtractAttachedFile("myimage.gif","c:\newimage.gif")
Otherwise, you can follow these three steps:
Step One - prep
- Load the image into a binary buffer
- Convert it to Hex
- Write out the text to a file
Step Two - edit script
- Copy/Paste that text into your WB script and assign it to a variable
Step Three - script runtime action
- Have your script plop the variable contents into a binary buffer using the BinaryPokeHex command
- Write out the binary buffer to a gif image
Code for the above might look like this:
Step One:
_gif = `c:\myimage.gif`
bbRaw = BinaryAlloc(FileSize(_gif))
bbHex = BinaryAlloc(FileSize(_gif))
BinaryRead(bbRaw, _gif)
_hex = BinaryPeekHex(bbRaw, 0, BinaryEodGet(bbRaw))
BinaryPokeHex(bbHex, 0, _hex)
BinaryWrite(bbHex, `c:\myimage.txt`)
Step Two:
_HexImage = `FFD8FFE000104A46494600 etc`
Step Three:
_size = 5000000
bb = BinaryAlloc(_size)
BinaryPokeHex(bb,0,_HexImage)
BinaryWrite(bb, "c:\newimage.gif")
Article ID: W17949
Filename: Store Image in WBT Script.txt
File Created: 2011:11:30:11:39:00
Last Updated: 2011:11:30:11:39:00