// Prepare the Image for the Selection Layer.
// Get ImageData of the image by drawing it in a temporary canvas...
ScratchCanvas scratch = new ScratchCanvas(m_destinationWidth, m_destinationHeight);
Context2D context = scratch.getContext();
context.drawImage(m_imageJSO, m_x, m_y, m_width, m_height, 0, 0, m_destinationWidth, m_destinationHeight);
ImageData imageData = context.getImageData(0, 0, m_destinationWidth, m_destinationHeight);
// Now draw the image again, replacing each color with the color key
scratch.clear();
Color rgb = Color.fromColorString(m_picture.getColorKey());
context.putImageData(new RGBIgnoreAlphaImageDataFilter(rgb.getR(), rgb.getG(), rgb.getB()).filter(imageData, true), 0, 0);
// Load the resulting image from the temporary canvas into the selection Image
String dataURL = scratch.toDataURL();