Ejemplo n.º 1
0
 /**
  * This implementation of <code>nativeToJava</code> converts a platform specific representation of
  * an image to java <code>ImageData</code>.
  *
  * @param transferData the platform specific representation of the data to be converted
  * @return a java <code>ImageData</code> of the image if the conversion was successful; otherwise
  *     null
  * @see Transfer#javaToNative
  */
 public Object nativeToJava(TransferData transferData) {
   ImageData imgData = null;
   if (transferData.length > 0) {
     long /*int*/ loader = OS.gdk_pixbuf_loader_new();
     try {
       OS.gdk_pixbuf_loader_write(loader, transferData.pValue, transferData.length, null);
       OS.gdk_pixbuf_loader_close(loader, null);
       long /*int*/ pixbuf = OS.gdk_pixbuf_loader_get_pixbuf(loader);
       if (pixbuf != 0) {
         Image img = Image.gtk_new_from_pixbuf(Display.getCurrent(), SWT.BITMAP, pixbuf);
         imgData = img.getImageData();
         img.dispose();
       }
     } finally {
       OS.g_object_unref(loader);
     }
   }
   return imgData;
 }
Ejemplo n.º 2
0
  /**
   * This implementation of <code>javaToNative</code> converts an ImageData object represented by
   * java <code>ImageData</code> to a platform specific representation.
   *
   * @param object a java <code>ImageData</code> containing the ImageData to be converted
   * @param transferData an empty <code>TransferData</code> object that will be filled in on return
   *     with the platform specific format of the data
   * @see Transfer#nativeToJava
   */
  public void javaToNative(Object object, TransferData transferData) {
    if (!checkImage(object) || !isSupportedType(transferData)) {
      DND.error(DND.ERROR_INVALID_DATA);
    }
    if (OS.GTK_VERSION < OS.VERSION(2, 4, 0)) return;

    ImageData imgData = (ImageData) object;
    if (imgData == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    Image image = new Image(Display.getCurrent(), imgData);
    long /*int*/ pixbuf = ImageList.createPixbuf(image);
    if (pixbuf != 0) {
      String typeStr = "";
      if (transferData.type == JPEG_ID) typeStr = "jpeg";
      else if (transferData.type == PNG_ID) typeStr = "png";
      else if (transferData.type == BMP_ID) typeStr = "bmp";
      else if (transferData.type == EPS_ID) typeStr = "eps";
      else if (transferData.type == PCX_ID) typeStr = "pcx";
      else if (transferData.type == PPM_ID) typeStr = "ppm";
      else if (transferData.type == RGB_ID) typeStr = "rgb";
      else if (transferData.type == TGA_ID) typeStr = "tga";
      else if (transferData.type == XBM_ID) typeStr = "xbm";
      else if (transferData.type == XPM_ID) typeStr = "xpm";
      else if (transferData.type == XV_ID) typeStr = "xv";
      byte[] type = Converter.wcsToMbcs(null, typeStr, true);
      long /*int*/[] buffer = new long /*int*/[1];
      long /*int*/[] len = new long /*int*/[1];
      if (type == null) return;
      OS.gdk_pixbuf_save_to_bufferv(pixbuf, buffer, len, type, null, null, null);
      OS.g_object_unref(pixbuf);
      transferData.pValue = buffer[0];
      transferData.length = (int) (len[0] + 3) / 4 * 4;
      transferData.result = 1;
      transferData.format = 32;
    }
    image.dispose();
  }