0 Replies Latest reply on Aug 8, 2007 10:46 PM by Paritosh Bisi

    AIR Image copy paste...

    Paritosh Bisi
      Hi all...

      Can any body help in copying and pasting an image from the clipboard,
      that is to copy an image and paste it inside our AIR application. I am
      using the following code but not getting the result.

      ..............................
      //for image paste
      public function readClipboardImage():void
      {
      ClipboardManager.accessClipboard(pasteImage);
      }

      public function pasteImage():void
      {
      var data:BitmapData =
      ClipboardManager.data.dataForFormat(TransferableFormats.BITMAP_FORMAT)
      as BitmapData;

      //encode the bitmapdata to an image
      var img:Image = encodeImage(data);
      myCanvas.addChild(img);


      }

      private function encodeImage(data:BitmapData):Image
      {
      // write transfer object's data to file
      var stream:FileStream = new FileStream();
      var matrix:Matrix = new Matrix();
      matrix.translate( 0 - ( data.rect.x + 1 ), 0 -
      ( data.rect.y + 1 ) );
      data.draw( data, matrix );

      var jpg:* = null;
      var jpegEncoder:JPEGEncoder = new JPEGEncoder();
      jpg = jpegEncoder.encode(data);

      var file:File =
      File.applicationResourceDirectory.resolve("tmp.jpg");
      stream.open( file, FileMode.WRITE );
      stream.writeBytes(jpg, 0, 0);
      stream.close();

      // now we can load the image back in
      var img:Image = new Image();
      img.load(file.nativePath);
      imgPaste.source = img.source;
      return img;

      }