Encode Your Images "Base64 Binary"

Version: 1.01.20 - last update: Sunday, September 27, 2009, 13:00:00

Previous EntryTips & Tricks HomeNext Entry 


Another way to encode and store picture-data inside your classes.

Intro

Since VFP 7.0 we’ve got native VFP language support to convert any kind of binary data into ASCII byte streams back and forth. One of the many cool things we can do using this feature is encoding binary image data to be stored inside HTML pages and/or XML tags. The encoding is called „Encoded Base64 Binary“. It can be accessed using VFP’s STRCONV(...13) and STRCONV(...14) function. Below you can find a little demo showing one way to use this. Copy&Paste it to a new VFP program window and run it.

*\\ -----------------------------------------------
SET PROCEDURE TO SYS(16) ADDITIVE
_SCREEN.ADDOBJECT("oFox","FoxImage")
_SCREEN.oFox.VISIBLE = .T.
HIDE WINDOW ALL
WAIT WINDOW "Press any key to continue..."
_SCREEN.REMOVEOBJECT("oFox")
SHOW WINDOW ALL
RETURN
*//
DEFINE CLASS FoxImage AS IMAGE
    PictureType = "Gif"
    HEIGHT = 40
    WIDTH = 40
  
    PROCEDURE INIT
      WITH THIS
            .PICTUREVAL = .GetImageData()
        ENDWITH
    ENDPROC

    PROCEDURE GetImageData
    *\\ EB64 encoded picture data:
    LOCAL cBitMap AS STRING
    TEXT TO cBitMap NOSHOW FLAGS 1 PRETEXT 1+2+4+8
R0lGODlhnACoAIAAAAAAAP///yH5BAAAAAEALAAAAACcAKgAAAL+jI+py+
0Po5y02ouz3rz7D4biSJbmiaZqCABWC6/y3MCxZN/0vuY27mvxhqXgD3IM
6IhMjtGQrAkRy6a1EkxUF9vt9cvIKrzaKZUMBou55nD7/E6rfQ40NH6wy4
f0h96utyfTh4QHVxcoeLJW6ILoKGWoiEIIBOl2iZk5uVhp6Sd5yJniOfEX
mpc4qlFqiqoatQrS6rpZZqspO5vj9Ip6+6vbqAqKm2ociSxcHPz5eMG7TB
Htcaqc3Lwc2+t7/bgtfUdc28gNLky9ez3OnJ123hHIPuxuBR//Ox9BK3eP
v15vWro9/rjtC4hl4JeCBsuRYjgIIbRg+jJAfOjtn7f+iqw4fvCYMOPFjx
JJZqyWDSSGkepmEFO58iXKkzMF0mQxxYjOnQ4j0oRp8Qk9nWNKdvxp9N1O
ljVthhvKtKnAp7WSHn1xkyoRfUC1dsp6x+uoilbFmuBY1iwJtGDVUjLa1a
3UmHIXWk1bt2HHvE2Atu2LtyU+aXFNkiQc2PBHbYnnDtbV2HEvyH/fjqjs
U1DhsGMxF4kMpbMi0KEnkda71rTnz3xdjV6tFfbl06I1yw5He29rHK9vI3
69m7dt34R7E4esOvfo5MdXNVf33HRn5cE/U68++zp2EZuhbceqnc33kNH3
jSe/tTzVqIfPV+UTHl38VO5Dwq9vUz0b/ev+uxfCnx8NaPDHCXtXhQEgMA
KGMt8c4clDIEH+RXJQggbGtFF8ESbjEkUT3nLFhRNl+KESDebSQyL8bFDi
iBuquCJ4J37TIYkiwjEjjZkddKOJNzbXo1M8qsQIXdxpCKOIRVqU3YIeXi
jUZNDtAIuBUcaD03zjkLUki7cFCR4WLoJJn0kbHiMmeWSWKVlEX61Zxkxn
ijKbmxoxAdqDZcGJ1ZFO/mOPb1rumWMRPBDZIpXwJcWnhUoWqtaVMiZopk
L2OacUT6gBl95SWc75Qo1LkZaolNYR9WeBz1m6aG1Z9qbqZapCKgWApRpZ
3619OgpqMZTq6syvtFKKCbHG2dWD5XbAfhNja8sy22xez2LD6pSB9qpJtB
g2emmm2qrJLTkSflvVtMWOW+22w4rDXFfkqmBuuXKui6ZzIL27oyyYJXut
spL2Q+9Ro2LrmrHDGQwwwQi7sXCmDTv4MLIR9zsxYApXHDDC8VbsI8edep
weyPeJTOXFE2dMcsoqr8xyyy4zUAAAOw==
    ENDTEXT
    *\\ Convert back to binary image format:
    RETURN STRCONV(cBitMap, 14)
    ENDPROC
ENDDEFINE
*// -----------------------------------------------

BTW: There is no need to keep the EB64 code-block starting at column #1. You may indent it using tabs or spaces as you like. The PRETEXT value 15 will remove these leading blanks for you before assigning the final content to the cBitMap variable!

Check it out and let me know what you have seen ;-)


Previous EntryTips & Tricks HomeNext Entry

2 comments:

  1. Neat, but how would one use this in HTML? I'm assuming that viewers of the HTML would like to see the image rather than the Gobbley Gook.

    ReplyDelete
  2. This is a VFP technique. I would use Pearl, PHP or ar Java Script instead while developing HTML pages

    ReplyDelete