Exemplo n.º 1
0
  /** @return A BufferedImage created from nsImagePtr, or null. */
  public BufferedImage toImage() {
    if (ptr == 0) return null;

    final Dimension2D size = nativeGetNSImageSize(ptr);
    final int w = (int) size.getWidth();
    final int h = (int) size.getHeight();

    final BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
    final DataBufferInt dbi = (DataBufferInt) bimg.getRaster().getDataBuffer();
    final int[] buffer = SunWritableRaster.stealData(dbi, 0);
    nativeCopyNSImageIntoArray(ptr, buffer, w, h);
    SunWritableRaster.markDirty(dbi);
    return bimg;
  }
Exemplo n.º 2
0
  static {
    SunWritableRaster.setDataStealer(
        new SunWritableRaster.DataStealer() {
          public byte[] getData(DataBufferByte dbb, int bank) {
            return dbb.bankdata[bank];
          }

          public short[] getData(DataBufferUShort dbus, int bank) {
            return dbus.bankdata[bank];
          }

          public int[] getData(DataBufferInt dbi, int bank) {
            return dbi.bankdata[bank];
          }

          public StateTrackableDelegate getTrackable(DataBuffer db) {
            return db.theTrackable;
          }

          public void setTrackable(DataBuffer db, StateTrackableDelegate trackable) {
            db.theTrackable = trackable;
          }
        });
  }