Hello, in your requestResource() method it is necessary to decode the Base64 String. For that purpose you can simply make use of the code below:
Code:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.m2g.ExternalResourceHandler;
import javax.microedition.m2g.ScalableImage;
public class SVGLoad implements ExternalResourceHandler {
public void requestResource(final ScalableImage scalableImage,
final String Str) {
final InputStream iStream;
System.out.println("Request For Resource " + Str);
try {
if (Str.startsWith("data:image")) {
int start = Str.indexOf("base64,") + 7;
String encoded = Str.substring(start);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Base64.decode(encoded, bos);
iStream = new ByteArrayInputStream(bos.toByteArray());
scalableImage.requestCompleted(Str, iStream);
return;
} else {
iStream = getClass().getResourceAsStream(Str);
if (iStream == null) {
System.out.println("Failed to load " + Str + "!");
}
scalableImage.requestCompleted(Str, iStream);
}
} catch (final IOException e) {
e.printStackTrace();
}
}
}
Bookmarks