Java-based Base64 Images in IE
inlineimage.zipintroduction
IE doesn't support inline Base64 encoded images (except in mht format files). There are several workarounds for this problem, but I didn't found a solution in Java.
Here is one. Base64 encoded string is pased to an object named InlineImage;
it will, depending on which method you invoke, write a segment of html code which is just an applet tag with inlineimage.class as it's code, or just return the applet object(In other browser, img tag will replace the applet tag).
See the sample code below :
InlineImage.insertImage("png","30","30",
"iVBORw0KGgoAAAANSUhEUgAAABIAAAARCAIAAABfOGuuAAAAAXNSR0IArs4c6QAAAARnQU1B"+
"AACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA"+
"AKhJREFUOE+dU0ESgCAIrIMv7RE9rAf0NCoXF1QmLcdxUFkWVlxFZPkxbhhGSkn27VmdjS3O"+
"1c7Oi2HOQ/IEHrYGwrYENZj3U0CJYlcOWbORhJjeuH2YpNaDDMva0sZsmeob7ClgCOslAckM"+
"G5R3kgz1CNkawl6P9rn1fevy+td7hYWpImIsSbmjquwvPXFIlYTta13L9nXhmKfBgPQFsMtx"+
"HvwAfp9J4wI0xVg56k4v+AAAAABJRU5ErkJggg=="
);
var iimg = InlineImage.createImage("png","30","30",
"iVBORw0KGgoAAAANSUhEUgAAABIAAAARCAIAAABfOGuuAAAAAXNSR0IArs4c6QAAAARnQU1B"+
"AACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA"+
"AKhJREFUOE+dU0ESgCAIrIMv7RE9rAf0NCoXF1QmLcdxUFkWVlxFZPkxbhhGSkn27VmdjS3O"+
"1c7Oi2HOQ/IEHrYGwrYENZj3U0CJYlcOWbORhJjeuH2YpNaDDMva0sZsmeob7ClgCOslAckM"+
"G5R3kgz1CNkawl6P9rn1fevy+td7hYWpImIsSbmjquwvPXFIlYTta13L9nXhmKfBgPQFsMtx"+
"HvwAfp9J4wI0xVg56k4v+AAAAABJRU5ErkJggg=="
);
Usage
InlineImage.setcodebase("your_path_to_the_class_file"); // default is current dir
InlineImage.insertImage(image_type, image_width, image_height, base64data);
result_element = InlineImage.createImage(image_type, image_width, image_height, base64data);
Include inlineimage.js before you invoke these two functions.
In both functions there are four parameters (in order) :
image type,
image width,
image height, and the
base64 data.
The applet will automatically resize image to ths size you specified, and the image types that have been tested include
gif, png, and jpg.
In fact the three little pinky hairy balls at the top-right corner are in gif, png , jpg format, respectively.
Requisites
There are three requisite files:
inlineimage.class for drawing image,
Base64Coder.class for base64 codec, and
inlineimage.js for the InlineImage object.
I've zipped them together in
inlineimage.zip so you can find them in the zip file; just place all of them in the same directory, or use InlineImage.setcodebase to indicate where you put these two class files.
The Java Source Code
If you are interested in the java source code, here it is :
inlineimage.java.
Base64Coder is provided by
Christian d'Heureuse and the coder homepage is
here. Thanks for Christian I don't have to write it over.
Environment
This auxiliary object have been tested on Internet Explorer 6.02, Mozilla Firefox 2.0.0.11, Opera 9.24 and Safari 3.0.4; all these tests are conducted under Windows XP (SP2).
License
All these code are released under the
Attribution-NonCommercial-ShareAlike 2.0 Taiwan
license.