# How to keep 'Alpha Channel' data with PNGEncoder?

**URL:** <https://forum.kirupa.com/t/how-to-keep-alpha-channel-data-with-pngencoder/323934>\
**Category:** flash\
**Created:** [July 25, 2011, 6:19am UTC](https://forum.kirupa.com/t/how-to-keep-alpha-channel-data-with-pngencoder/323934 "2011-07-25T06:19:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnnieCanoe](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@AnnieCanoe](https://forum.kirupa.com/u/AnnieCanoe)\
**Post date:** [July 25, 2011, 6:19am UTC](https://forum.kirupa.com/t/how-to-keep-alpha-channel-data-with-pngencoder/323934/1 "2011-07-25T06:19:36Z")

</div>

Hi! I’m trying to import an image and assign it to a Loader object, which works just fine, though I want to use the PNGEncoder rather than a the JPGEncoder, because if the source image has an alpha channel (transparency) I want that data preserved.

The code, or the encoder, or something is preventing or deleting the alpha channel data. What should be transparent is showing as white.

I anyone could point out the error I’d much appreciate it… This is my last major task and has been stumping me for months!

Thanks!

(Snip of code is below)

```auto

import com.adobe.images.PNGEncoder;

function Editor_fileLoadedCallback(event:Event):void
  {
        bytes=fileRef.data;
        trace("Editor_fileLoadedCallback(event:Event) fileLoaded Complete, " + bytes.length + " bytes.");
        _imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onByteLoad);
        _imageLoader.loadBytes(bytes);
  }
   
  function _onByteLoad(e:Event):void 
  {
        var scaleWidth:int = 300;
        var content:Bitmap = _imageLoader.content as Bitmap;
        content.smoothing = true;
        var origWidth:Number = content.width;
        content.width = scaleWidth;
        content.scaleY = 1 / (origWidth / scaleWidth);
        var m:Matrix = new Matrix(content.scaleX, 0, 0, content.scaleY);
        var smaller:BitmapData = new BitmapData(scaleWidth, content.height, false);
        smaller.draw(content, m);
        _loaderByteArray = PNGEncoder.encode(smaller); 
        _loader.loadBytes(_loaderByteArray);
  }

```
