Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

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

From Wikipedia, the free encyclopedia
Computing desk
< September 10 << Aug | September | Oct >> September 12 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


September 11

[edit]

What does the following base64 encoded PNG image look like?

[edit]

What does the following base64 encoded PNG image look like?

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)reply

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)reply
Thank you very much!! My other car is a cadr (talk) 04:23, 12 September 2015 (UTC)reply
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)reply
Resolved