Fields Summary |
---|
protected RasterImage | brokenImageDefault, broken image returned if an image cannot be loaded. |
protected RasterImage | loadingImageImage used to symbolize loading state for an image. |
static final String | BASE64_PREFIXHREF prefix for all Base64 encoded images |
static final int | BROKEN_IMAGE_COLORColor used for broken content. |
static final int | LOADING_IMAGE_COLORColor used for loading content. |
static final String | BASE64_JPG_HREF_PREFIXHREF prefix for Base64 encoded JPEG files |
static final String | BASE64_JPG_HREF_PREFIX2HREF prefix for Base64 encoded JPEG files |
static final String | BASE64_PNG_HREF_PREFIXHREF prefix for Base64 encoded PNG files |
static final String | BASE64_HREF_PREFIXHREF prefix for Base64 encoded images with unspecified media type |
static final int | BASE64_JPG_HREF_PREFIX_LENGTHLength of the HREF prefix for Base64 encoded JPEG files |
static final int | BASE64_JPG_HREF_PREFIX2_LENGTHLength of the HREF prefix for Base64 encoded JPEG files |
static final int | BASE64_PNG_HREF_PREFIX_LENGTHLength of the HREF prefix for Base64 encoded PNG files |
static final int | BASE64_HREF_PREFIX_LENGTHLength of the HREF prefix for Base64 encoded images with
unspecified media type |
Methods Summary |
---|
public RasterImage | createImage(byte[] imageData)Creates a RasterImage from a byte array.
Image img = Image.createImage(imageData, 0, imageData.length);
return (new RasterImage(img));
|
public RasterImage | createImage(int[] imageData, int width, int height)Creates a RasterImage from an int array containing the pixel data
Image img = Image.createRGBImage(imageData, width, height, true);
return new RasterImage(img);
|
protected void | createPlaceholderImages()
int[] argb = {BROKEN_IMAGE_COLOR};
Image image = Image.createRGBImage(argb, 1, 1, true);
brokenImage = new RasterImage(image);
argb = new int[] {LOADING_IMAGE_COLOR};
image = Image.createRGBImage(argb, 1, 1, true);
loadingImage = new RasterImage(image);
|
public RasterImage | getBrokenImage()Returns the image that should be used to represent an
image which could not be loaded.
return brokenImage;
|
public RasterImage | getEmbededImage(java.lang.String uri)Utility method to get an Image from Base64
encoded image data
int startAt = 0;
if (uri.startsWith(BASE64_PNG_HREF_PREFIX)) {
startAt = BASE64_PNG_HREF_PREFIX_LENGTH;
} else if (uri.startsWith(BASE64_JPG_HREF_PREFIX)) {
startAt = BASE64_JPG_HREF_PREFIX_LENGTH;
} else if (uri.startsWith(BASE64_JPG_HREF_PREFIX2)) {
startAt = BASE64_JPG_HREF_PREFIX2_LENGTH;
} else if (uri.startsWith(BASE64_HREF_PREFIX)) {
startAt = BASE64_HREF_PREFIX_LENGTH;
} else {
return brokenImage;
}
InputStream is = new Base64StringStream(uri, startAt);
is = new Base64DecodeStream(is);
// Base64 encodes 3 bytes with 4 characters
byte[] data = new byte[(uri.length() - startAt) * 3 / 4];
try {
Image img = Image.createImage(is);
return (new RasterImage(img));
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
return brokenImage;
} catch (java.lang.IllegalArgumentException iae) {
iae.printStackTrace();
return brokenImage;
} finally {
try {
is.close();
} catch (java.io.IOException ioe) {
}
}
|
public RasterImage | getExternalImage(java.lang.String href)Utility method to turn an image href into an Image. This assumes
that the href points to an external resource. This can
be tested on the href with the isDataURI method.
System.out.println("getExternalImage(), Image href = " + href);
Image img = null;
StreamConnection c = null;
InputStream s = null;
try {
c = (StreamConnection)Connector.open(href);
s = c.openInputStream();
img = Image.createImage(s);
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("returning broken image");
return brokenImage;
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
System.out.println("returning broken image");
return brokenImage;
} finally {
try {
if (s != null)
s.close();
if (c != null)
c.close();
} catch (IOException ioe) {
//note : we have already read the image successfully.
//So don't fail, simply print stacktrace.
ioe.printStackTrace();
}
}
return (new RasterImage(img));
|
public RasterImage | getLoadingImage()Returns the image that should be used to represent
an image which is loading.
return loadingImage;
|
public boolean | isDataURI(java.lang.String uri)Returns true if the input uri is a data uri.
return (uri.startsWith(BASE64_PREFIX));
|