예제 #1
0
  @Override
  public void getRgb(
      int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
    Asserts.checkState(isReady(), "Cannot getRgb() a non-ready image");

    if (canvas == null) {
      canvas = img.getOwnerDocument().createCanvasElement();
      canvas.setHeight(img.getHeight());
      canvas.setWidth(img.getWidth());
      canvas.getContext2d().drawImage(img, 0, 0);
      // img.getOwnerDocument().getBody().appendChild(canvas);
    }

    Context2d ctx = canvas.getContext2d();
    ImageData imageData = ctx.getImageData(startX, startY, width, height);
    CanvasPixelArray pixelData = imageData.getData();
    int i = 0;
    int dst = offset;
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        int r = pixelData.get(i++);
        int g = pixelData.get(i++);
        int b = pixelData.get(i++);
        int a = pixelData.get(i++);
        rgbArray[dst + x] = a << 24 | r << 16 | g << 8 | b;
      }
      dst += scanSize;
    }
  }
예제 #2
0
  public static final String toDataURL(final ImageElement element) {
    final ScratchCanvas canvas = new ScratchCanvas(element.getWidth(), element.getHeight());

    canvas.getContext().drawImage(element, 0, 0);

    return canvas.toDataURL();
  }
예제 #3
0
 public void triggerSingleImageLoading(String imageFileName, GeoImage geoi) {
   ImageElement img = externalImageTable.get(imageFileName);
   ImageWrapper.nativeon(img, "load", new ImageLoadCallback2(geoi));
   ImageErrorCallback2 i2 = new ImageErrorCallback2(geoi);
   ImageWrapper.nativeon(img, "error", i2);
   ImageWrapper.nativeon(img, "abort", i2);
   img.setSrc(externalImageSrcs.get(imageFileName));
 }
예제 #4
0
  public static final String toDataURL(ImageElement element, DataURLType mimetype, double quality) {
    if (null == mimetype) {
      mimetype = DataURLType.PNG;
    }
    ScratchCanvas canvas = new ScratchCanvas(element.getWidth(), element.getHeight());

    canvas.getContext().drawImage(element, 0, 0, element.getWidth(), element.getHeight());

    return canvas.toDataURL(mimetype, quality);
  }
예제 #5
0
 private void resetIcon() {
   if (null == product.getIconKey()) {
     icon.setSrc("images/noicon.gif");
     containerPanel.getWidget(0).setVisible(false);
   } else {
     containerPanel.getWidget(0).setVisible(true);
     icon.setSrc(
         "gwt_marketplace/productImage?key=" + product.getId() + "&ik=" + product.getIconKey());
     icon.getStyle().setDisplay(Display.BLOCK);
   }
 }
예제 #6
0
 /**
  * Img elements needs some special handling in custom layout. Img elements will get their onload
  * events sunk. This way custom layout can notify parent about possible size change.
  */
 private void initImgElements() {
   NodeList<Element> nodeList = getElement().getElementsByTagName("IMG");
   for (int i = 0; i < nodeList.getLength(); i++) {
     ImageElement img = ImageElement.as(nodeList.getItem(i));
     DOM.sinkEvents(img, Event.ONLOAD);
   }
 }
예제 #7
0
  /** Tests createLoadEvent(). */
  public void testTriggerLoadEvent() {
    ImgEventListener listener = new ImgEventListener("load");
    Event.setEventListener(parent, listener);
    Event.setEventListener(img, listener);

    img.dispatchEvent(Document.get().createLoadEvent());

    assertTrue("Expected img to receive event", listener.imgReceived);
  }
예제 #8
0
  /**
   * Tests createErrorEvent().
   *
   * <p>Failed in all modes due to HtmlUnit bug: https://sourceforge.net/tracker/?func
   * =detail&aid=2888342&group_id=47038&atid=448266
   */
  @DoNotRunWith({Platform.HtmlUnitBug})
  public void testTriggerErrorEvent() {
    ImgEventListener listener = new ImgEventListener("error");
    Event.setEventListener(parent, listener);
    Event.setEventListener(img, listener);

    img.dispatchEvent(Document.get().createErrorEvent());

    assertTrue("Expected child to receive event", listener.imgReceived);
  }
 @Override
 public void reset() {
   Preconditions.checkState(this.listener != null);
   this.listener = null;
   avatar.setSrc(null);
   name.setInnerText(null);
   address.setInnerText(null);
   for (Widget child : self.getChildren()) {
     child.removeFromParent();
   }
 }
예제 #10
0
 public ImageElement getInternalImage(ImageResource resource) {
   ImageElement img = Document.get().createImageElement();
   img.setSrc(resource.getSafeUri().asString());
   return img;
 }
예제 #11
0
  @Override
  public void draw(Context2d context) {
    String file = getEnvObject().getCurrentRepresentation().getIcon();
    Path2D objectPath =
        DrawingUtils.freedomPolygonToPath(
            (FreedomPolygon) getEnvObject().getCurrentRepresentation().getShape());
    Rectangle2D box = objectPath.getBounds2D();
    objectBounds = objectPath.getBounds();

    rotation = getEnvObject().getCurrentRepresentation().getRotation();
    dx = getEnvObject().getCurrentRepresentation().getOffset().getX();
    dy = getEnvObject().getCurrentRepresentation().getOffset().getY();
    context.translate(dx, dy);
    context.rotate(rotation);
    WebGraphics g = new WebGraphics(context);
    if (ImageUtils.CachedImages.containsKey(OBJECT_PATH + file)) {
      Image im = ImageUtils.CachedImages.get(OBJECT_PATH + file);
      ImageElement ie = ImageElement.as(im.getElement());
      // ghostPath = new Rectangle(ie.getWidth(),ie.getHeight());
      ghostPath = objectBounds;
      context.drawImage(ie, 0, 0, box.getWidth(), box.getHeight());

      // draw box surronding object
      // draw the border
      context.setLineWidth(1);
      g.setColor(new Color(137, 174, 32));
      g.draw(box);

    } else {
      //        	//TODO: Cache path
      //    		Paint paint = new Paint();
      //    		paint.setStyle(Style.FILL);
      //
      //    		ghostPath = new Path();
      //    		objectPath.transform(drawingMatrix, ghostPath);
      //    		int fillColor=-1;
      //    		try
      //    		{
      //    			fillColor =
      // Color.parseColor(getEnvObject().getCurrentRepresentation().getFillColor());
      //    			paint.setColor(fillColor);
      //    			canvas.drawPath(ghostPath, paint);
      //    		}
      //    		catch(IllegalArgumentException ex)
      //    		{
      //    			System.out.println("ParseColor exception in fill");
      //    		}
      //    		int borderColor=-1;
      //    		try
      //    		{
      //    			borderColor =
      // Color.parseColor(getEnvObject().getCurrentRepresentation().getBorderColor());
      //    			paint.setColor(borderColor);
      //    			paint.setStyle(Style.STROKE);
      //    			canvas.drawPath(ghostPath, paint);
      //    		}
      //    		catch(IllegalArgumentException ex)
      //    		{
      //    			System.out.println("ParseColor exception in border");
      //    		}
    }
    context.rotate(-rotation);
    context.translate(-dx, -dy);
  }
  /**
   * Draws an input image at a given position on the canvas. Resizes image according to specified
   * width and height.
   *
   * <p>We recommend that the pixel and coordinate spaces be the same to provide consistent
   * positioning and scaling results
   *
   * @param img The image to be drawn
   * @param offsetX x coord of the top left corner in the destination space
   * @param offsetY y coord of the top left corner in the destination space
   * @param width the size of the image in the destination space
   * @param height the size of the image in the destination space
   */
  public void drawImage(
      ImageElement img, double offsetX, double offsetY, double width, double height) {

    impl.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), offsetX, offsetY, width, height);
  }
 /**
  * Draws an input image to a specified position on the canvas. Size defaults to the default
  * dimensions of the image.
  *
  * @param img the image to be drawn
  * @param offsetX x coord of the top left corner in the destination space
  * @param offsetY y coord of the top left corner in the destination space
  */
 public void drawImage(ImageElement img, double offsetX, double offsetY) {
   drawImage(img, offsetX, offsetY, img.getWidth(), img.getHeight());
 }
 @SuppressWarnings("unused")
 private void firePopupImageLoadedEvent(ImageElement image) {
   EventBus.INSTANCE.fireEvent(
       new PopupImageLoadedEvent(image.getOffsetWidth(), image.getOffsetHeight()));
 }
예제 #15
0
 @Override
 public float width() {
   return img == null ? 0 : scale.invScaled(img.getWidth());
 }
예제 #16
0
 @Override
 public float height() {
   return img == null ? 0 : scale.invScaled(img.getHeight());
 }
 @Override
 public void setAvatarUrl(String url) {
   avatar.setSrc(url);
 }
예제 #18
0
파일: GwtBitmap.java 프로젝트: QiXi/vtm
 public GwtBitmap(Image data) {
   ImageElement imageElement = ImageElement.as(data.getElement());
   pixmap = new Pixmap(imageElement);
   image = data;
 }