According to the WhatWG spec for <canvas>, getImageData() returns a
CavasPixelArray, which is an array of bytes. What if you created a
JavaScriptObject to represent it? Does GWT thunk to bytes across the
JSNI boundary OK? I know it won't pass arrays of anything back, but
individual elements maybe:

import com.google.gwt.core.client.JavaScriptObject;

public class CanvasPixelArray extends JavaScriptObject {
    protected CanvasPixelArray() {
        //required by GWT
    }

    public native int getLength() /*-{
        return this.length;
    }-*/;

    public native byte getPixelByte(int pos) /*-{
        return this[pos];
    }-*/;
}


//then, create one in your code:
public byte[] getBitmap(Element canvasElement, int left, int top, int
width, int height) {
    //then, create one in your code:
    CanvasPixelArray cpa = getCPA(canvasElement, left, top, width,
height);
    byte[] pixelBytes = new byte[cpa.length()];
    for (int i = 0; i < cpa.length(); i++) {
       pixelBytes[i] = cpa.getPixelByte(i);
    }
    return pixelBytes;
}

private native CanvasPixelArray getCPA(Element canvas, int sx, int sy,
int sw, int sh) /*-{
    return canvas.getContext("2d").getImageData(sx, sy, sw, sh);
}-*/;


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to