arrays - Converting 32x32 StdPicture icons to PNG -


i trying convert stdpicture png before encoding base64 sent on xml. i've gotten base64 encoding portion down (see near end of function encodeimagetobase64()) having trouble converting stdpicture object png byte array.

here's function:

private function encodeimagetobase64(byref image stdpicture) string   dim xmldoc domdocument60   dim xmlnode msxml2.ixmldomelement   dim bcolor() byte   dim bmask() byte   dim bimage() byte   dim lcrctable() long   dim lwidth long   dim lheight long   encodeimagetobase64 = vbnullstring    if image nothing     exit function   end if    call makecrc32table(lcrctable)   call iconpictoarrays(image, bcolor, bmask, lwidth, lheight)   if not createpngbytearray(bimage, lwidth, lheight, bcolor, bmask, lcrctable)     debug.assert false     exit function   end if   'call getpicturebits(bimage, image)    set xmldoc = new domdocument60   set xmlnode = xmldoc.createelement("b64")   xmlnode.datatype = "bin.base64"   xmlnode.nodetypedvalue = bimage   encodeimagetobase64 = xmlnode.text    set xmlnode = nothing   set xmldoc = nothing end function 

the problem people wrote createpngbytearray intended function convert png's of 16x16. 32x32 icons fail assertion that's in function:

'create png (rfc-2083) image based on 16x16 icon's color , mask bitmaps public function createpngbytearray(byref btarget() byte, byval width long, byval _       height long, bcolor() byte, bmask() byte, lcrctable() long) boolean   dim bindex() byte   dim bpalette() byte   dim lpos long   dim lcrc long   dim x long   dim y long   dim z long   dim lpalsize long    if width > 16 or height > 16 exit function    lpalsize = rgbtopalette(bcolor, bmask, bindex, bpalette, width, height)    redim btarget(0 364 + lpalsize) byte '8+25+(12+lpalsize)+13+295+12-1    'png signature 'long val = -1991225785  'hex value = 89504e47   btarget(0) = 137   btarget(1) = 80   btarget(2) = 78   btarget(3) = 71   btarget(4) = 13   btarget(5) = 10   btarget(6) = 26   btarget(7) = 10   lpos = 8    'ihdr   call fliplongtoarray(13, btarget(), lpos)   call fliplongtoarray(pctihdr, btarget(), lpos + 4) 'add chunk flag   call fliplongtoarray(width, btarget(), lpos + 8)   call fliplongtoarray(height, btarget(), lpos + 12)   btarget(lpos + 16) = 8  'bit depth   btarget(lpos + 17) = 3  'color type   btarget(lpos + 18) = 0  'compression - none   btarget(lpos + 19) = 0  'filter   btarget(lpos + 20) = 0  'interlace   lcrc = crc32(btarget(), lpos + 4, lpos + 20, lcrctable())   call fliplongtoarray(lcrc, btarget(), lpos + 21)   lpos = lpos + 25    'plte   call fliplongtoarray(lpalsize, btarget(), lpos)   call fliplongtoarray(pctplte, btarget(), lpos + 4)   'add chunk flag   call copymemory(btarget(lpos + 8), bpalette(0), lpalsize)   lcrc = crc32(btarget(), lpos + 4, lpos + lpalsize + 7, lcrctable())   call fliplongtoarray(lcrc, btarget(), lpos + lpalsize + 8)   lpos = lpos + lpalsize + 12    'trns   call fliplongtoarray(1, btarget(), lpos)   call fliplongtoarray(pcttrns, btarget(), lpos + 4)  'add chunk flag   btarget(lpos + 8) = 0 'alpha   lcrc = crc32(btarget(), lpos + 4, lpos + 8, lcrctable())   call fliplongtoarray(lcrc, btarget(), lpos + 9)   lpos = lpos + 13    'idat   call fliplongtoarray(283, btarget(), lpos)   call fliplongtoarray(pctidat, btarget(), lpos + 4)  'add chunk flag   btarget(lpos + 8) = 24 '8=deflate + 16=512b lz77 window (rfc-1950)   btarget(lpos + 9) = 25 'so (compmethod*256 + addlflags) mod 31=0 (rfc-1950)   btarget(lpos + 10) = 1 '(rfc-1951)   btarget(lpos + 11) = 16 '272: len 0 (rfc-1951)   btarget(lpos + 12) = 1 '272: len 1   btarget(lpos + 13) = &hef '~272: nlen 0 (rfc-1951)   btarget(lpos + 14) = &hfe '~272: nlen 1   x = 0 15     btarget(lpos + 15 + z) = 0     call copymemory(btarget(lpos + 16 + z), bindex(y), 16)     y = y + 16     z = z + 17   next x   lcrc = adler32(btarget(), lpos + 15, lpos + 286)   call fliplongtoarray(lcrc, btarget(), lpos + 287) 'adler32 supposed safe leave empty, isn't   lcrc = crc32(btarget(), lpos + 4, lpos + 290, lcrctable())   call fliplongtoarray(lcrc, btarget(), lpos + 291)   lpos = lpos + 295    'iend   call fliplongtoarray(0, btarget(), lpos)   call fliplongtoarray(pctiend, btarget(), lpos + 4)   'add chunk flag   lcrc = crc32(btarget(), lpos + 4, lpos + 7, lcrctable())   call fliplongtoarray(lcrc, btarget(), lpos + 8)    createpngbytearray = true end function 

i've looked on code relentlessly have not done low-level programming (dealing bytes , whatnot) , have come far short.

is there way repurpose this, or other way able convert png images of size byte arrays? if i'm going using libraries /.dlls prefer standard microsoft ones.

thanks!

you can use property bag this

option explicit  private sub form_load()     dim encoded     string      encoded = encodeimagetobase64(loadpicture("d:\temp\aaa.gif"))     caption = "encoded size: " & len(encoded)     set picture = decodeimagefrombase64(encoded) end sub  private function encodeimagetobase64(byref image stdpicture) string     dim obag        propertybag      set obag = new propertybag     obag.writeproperty "i", image, nothing     vba.createobject("msxml2.domdocument").createelement("dummy")         .datatype = "bin.base64"         .nodetypedvalue = obag.contents         encodeimagetobase64 = .text     end end function  private function decodeimagefrombase64(byref base64 string) stdpicture     dim obag        propertybag     dim qh          long      on error goto qh     set obag = new propertybag     vba.createobject("msxml2.domdocument").createelement("dummy")         .datatype = "bin.base64"         .text = base64         obag.contents = .nodetypedvalue     end     set decodeimagefrombase64 = obag.readproperty("i", nothing) qh: end function 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -