dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: PNG Encoder Problem

  1. #1
    Member
    Join Date
    Jun 2008
    Location
    Amman, Jordan
    Posts
    44

    Question PNG Encoder Problem

    Hi,

    I have this code on a frame in Air file using Flash CS3:

    var spBoard:Sprite=new Sprite();
    this.addChild(spBoard);

    var shDrawing:Shape=new Shape();
    spBoard.addChild(shDrawing);

    shDrawing.graphics.beginFill(0xFFCC00);
    shDrawing.graphics.lineStyle(1, 0x666666);
    shDrawing.graphics.drawCircle(100, 100, 300);
    shDrawing.graphics.endFill();

    //==================================
    //Save PNG:
    import com.adobe.images.PNGEncoder;
    import flash.filesystem.*;
    btnSave.addEventListener(MouseEvent.CLICK, btnSave_CLICK);
    function btnSave_CLICK(e:MouseEvent):void {
    var BMP:BitmapData=new BitmapData(500,500);
    BMP.draw(shDrawing);
    var BA:ByteArray;
    BA=PNGEncoder.encode(BMP);
    var file= File.desktopDirectory.resolvePath("Image1.png");
    var filestream1:FileStream=new FileStream();
    filestream1.open(file,FileMode.WRITE);
    filestream1.writeByte(BA);
    filestream1.close();
    }

    and the line (filestream1.writeByte(BA)

    generate this error:

    1067: Implicit coercion of a value of type flash.utils:ByteArray to an unrelated type int.

    anybody can make it work?

    thanks a lot.
    Last edited by newemadzedan; 07-21-2008 at 05:43 AM.

  2. #2
    Member
    Join Date
    Jun 2008
    Location
    Amman, Jordan
    Posts
    44
    I knew the problem, it is
    filestream1.writeBytes(BA);

  3. #3
    Junior Member
    Join Date
    Aug 2008
    Posts
    3
    When you typed filestream1.writeByte(BA) you were writing a integer for a value, what you really want to do is write all the Bytes for your picture. So just add an s in filestream1.writeByte(BA); to filestream1.writeBytes(BA);

  4. #4
    supervillain gerbick's Avatar
    Join Date
    Jul 2000
    Location
    undecided.
    Posts
    18,978
    Quote Originally Posted by deepwaterblack
    When you typed filestream1.writeByte(BA) you were writing a integer for a value, what you really want to do is write all the Bytes for your picture. So just add an s in filestream1.writeByte(BA); to filestream1.writeBytes(BA);
    Thanks for clearing that one up... I seriously never knew the difference.

    Awesome.

    [ Hello ] | [ gerbick ] | [ Ω ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center