0 Replies Latest reply on Aug 13, 2012 5:56 AM by Leszekducker

    PNGEncoder lose transparent quality

    Leszekducker

      I've got problem with transparent using PNGEncoder class. When I encode BitmapData to png and use it as source of my Image, it looks terrible. I attach example. There are two images - first colorful and above him white with alpha gradient.

       

      Screen shot 2012-08-10 at 12.52.53 PM.png

      Screen shot 2012-08-10 at 12.55.29 PM.png

       

       

      I've used some other libraries like AsPngEncoder, but it didn't help. It's code I use:

       

       

                 

      var bd:BitmapData = new BitmapData(container.width, container.height, true, 0xffffff);
      bd.draw(container);
      var pngenc:PNGEncoder = new PNGEncoder();
      
      
      var pngByteArray:ByteArray = pngenc.encode(bd);
      
      
      container.source = pngByteArray;
      var fl:File = File.applicationStorageDirectory.resolvePath("./images/file.png");
      
      
      var fs:FileStream = new FileStream();
      fs.open(fl, FileMode.WRITE);
      fs.writeBytes(pngByteArray);
      fs.close();
      

       

      I've tried also new Air 3.3 feature:

       

      var pngByteArray:ByteArray = new ByteArray();
      bd.encode(new Rectangle(0,0,bd.width,bd.height), new flash.display.PNGEncoderOptions(), pngByteArray);
      

       

      but it doesn't help. When I save the same image 3-4 times it looks terrible.