class LienzoLayerUtils {

    public static String layerToDataURL(final LienzoLayer lienzoLayer,
                                        final DataURLType dataURLType,
                                        final int x,
                                        final int y,
                                        final int width,
                                        final int height,
                                        final String bgColor) {
        final com.ait.lienzo.client.core.shape.Layer layer = lienzoLayer.getLienzoLayer();
        final ScratchPad scratchPad = layer.getScratchPad();
        scratchPad.setPixelSize(width, height);
        if (null != bgColor) {
            scratchPad.getContext().setFillColor(bgColor);
            scratchPad.getContext().fillRect(0,
                                             0,
                                             width,
                                             height);
        }
        layer.drawWithTransforms(scratchPad.getContext(),
                                 1,
                                 new BoundingBox(x,
                                                 y,
                                                 width,
                                                 height));
        final String data = scratchPad.toDataURL(dataURLType,
                                                 1);
        scratchPad.clear();
        return data;
    }

}