Wikipedia:Reference desk/Archives/Computing/2015 September 11

= September 11 =

What does the following base64 encoded PNG image look like?
What does the following base64 encoded PNG image look like?

iVBORw0KGgoAAAANSUhEUgAAAtAAAAOQCAIAAACfGtETAAAAA3NCSVQFBgUzC42AAAAgAElEQVR4 nOzdT0gcW//v+/Lch0s90D9oZy0YSGfWwUDaWYsZxIxOixvUWTcGEp1phETPyI78SHSmCbh1Zkcw tDNb2EFnaQfZGO7vgCUkxFlKSEAHh2vBE9hyOeAd1D4+5arutv/U31XvFz9+PF3J1pW9jX56re/6 fjsuLy8VAAAAN/03vxcAAADkR+AAAACuI3AAAADXETgAAIDrCBwAAMB1BA4AAOA6AgcAAHAdgQMA ALiOwAEAAFxH4AAAAK4jcAAAANcROAAAgOsIHAAAwHUEDgAA4DoCBwAAcB2BAwAAuI7AAQAAXEfg AAAAriNwAAAA1xE4AACA6wgcAADAdQQOAADgOgIHAABwHYEDAAC4jsABAABcR+AAAACuI3AAAADX ETgAAIDrCBwAAMB1BA4AAOA6AgcAAHAdgQMAALiOwAEAAFxH4AAAAK4jcAAAANcROAAAgOsIHAAA wHUEDgAA4DoCBwAAcN0//F4AAADO0I608/Nz839X9ivm/xh4ONDZ2Zm+n/ZvXVAURem4vLz0ew0A ANRjGMahdmj+/6uX5i/pJ/rZz7NGPkiqJxWPxwceDiSTyeTtZG+6Nx6Pu7dmCAgcAICgMLcozP+v n+i6rjeeJ1qgxtT0/fToyOjAwwG2QNxG4AAAeE070nRdN3cpzLOPz39+9ndJakwdGR4ZeDgw8HAg eTvp72KkROAAAHjBMIzKfmV7Z7u8U774deH3cupJ9aTM5DEyPOL3WuRB4AAAuEg/0Sv7lfJOee/D ntufK9GduNqcMEs0zGoP7UhrOeJk+jOjI6MjwyNse7SJwAEAcJ52pG2Xt8s75eOvx458wEx/RlGU gYcD5sur/9H4DZTKfsWsCzEPdJpdWHYoO/5knD2PlhE4AACOKe+Ut3e2K/uV1io9zS0K8xaJmSRc vdGqHWmV/Uplv9L47ku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XV7RXCd42frHHGHzra kZYdytr/y9IzFLUYhpF/nLcfv6ox9fTHacB/KBA4/FHcKDZ1Zk+1IBqsHea8PyyW3y7Pvpi1P8/0 Z/Y+7PGfD3XYtzq2y9shOFW5hIe+69/nXs6pMbXB/zrZoez6u/Xz83O/F44AafCrKDeW+65/93ux qOL8/Dw3lqv6X23u5Zzfq0M4nJ+fZ4eyVz8p/F5OQwgcHjnUDmt9ixGoMTU3liNn4Ebr79YT3Yn6 X06Z/szHyke/V4p/O9QOUz2pqn/x+S+FZm2XtxPdibD8sOBIxXXFjWLxXfHGTqD0tEZr6o/1MlHe ERC1iv5SPandD7scmEJuBA63GIZR3CguvVmqX+tnTu0y6zM8Wxvko5/ohflCnbkbCuUdfpuanlr7 fc3+fPLZ5OrKqvfrATxG4HCe+a3/xguNubHc7ItZ+nHBQTfO4DDRvcNjhmH0PeizV/syVh6RQuBw UmW/svx2uf7dE95lwgP153GYMv2Ztd/XiLxuq9VCNNWTKr0v8e8f0UHgcEYj399TPamZFzO8m4Fn GinvWH+3zteke2q1EA1FmybAWQSOtjS4g50dys48n6GND3xxY3kHNQRuqNWgSVGUpTdLM89nvF8S 4C8CR4saiRpqTB1/Mj7zYobDcviu/lcsb7idVauFqBpTDz4dcIyCaCJwNK2RqJHoTsy+mGWYJwKo 1vEfNzOdUtwoTjydsD+nhSgijsDRhEaiRqY/M/tiljuuCLj847z9kIX3322qM0l87uXcwqsF75cE BAeBoyGNRA2uuSJcqs7y4KJmy/QTfXBosOrd17BMDwdcReC4wY1Rg2uuCK/iRnF

I tried various online tools to convert it, but those tools all show a half-cut-off version of the original image. My own code, however, manages to both encode and decode it fine. Now I'm kinda stuck since I'm not sure whether it's my own code that's broken or it's the online services that's broken.

Here's the Java code I used to encode it and decode it:

mBitmap = // image from somewhere ByteArrayOutputStream bao1 = new ByteArrayOutputStream; mBitmap.compress(Bitmap.CompressFormat.PNG, 10, bao1); byte[] ba11 = bao1.toByteArray; result = Base64.encodeToString(ba11, Base64.DEFAULT);

byte[] decodedString = Base64.decode(result, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

My other car is a cadr (talk) 13:35, 11 September 2015 (UTC)


 * The last line is 63 symbols long, but Base64 text must be a multiple of 4 symbols long. It can't be fixed by adding = because the final F ends with a 1 bit. If I decode the rest, I get a truncated PNG file (it ends halfway through an IDAT chunk). Something is truncating your Base64 output to about 4000 characters. -- BenRG (talk) 18:51, 11 September 2015 (UTC)
 * Thank you very much!! My other car is a cadr (talk) 04:23, 12 September 2015 (UTC)
 * BTW, since you said your own code produced the complete output this may be a useful time to consider good testings practices. I presume either your code was flawed and wasn't taking the correct input, or you weren't feeding it the correct input. A good way to try and avoid the former is to make sure you test different inputs. For example, if you purposely cut off the BASE64 output and your code was still producing the exact same output, there must be something wrong with your code. For the later, remember to always output what you are testing to a file yourself after you've used it for testing elsewhere so that you can be fairly certain you are testing the same data. (If you're testing locally then just make sure you always use the same file, altho making a copy can be useful to reduce the possibility of mistakes.) Nil Einne (talk) 16:25, 12 September 2015 (UTC)