1 Reply Latest reply on Jan 7, 2010 5:28 PM by Jason Szeto

    Bitmap & copyPixel of transparent gif

    Agenore990

      I wrote this code, but it shows me always a not transparent image…

       

      private var bitmap_mod:BitmapData = new BitmapData(1600, 1600,true);

      [Embed(source="/assets/terrain/gamemap_t0.gif",mimeType="image/jpeg")]
      private var Mountain01:Class;

      private var library:Object = {};
      var bma:BitmapAsset = new Mountain01() as BitmapAsset;
      library[0] = bma.bitmapData;

      var tile:Rectangle;
      tile = new Rectangle(0,0,140,140);

      bitmap_mod.copyPixels(library[0], tile, new Point(0, 0));

       

       

      Can Someone help me?

        • 1. Re: Bitmap & copyPixel of transparent gif
          Jason Szeto Level 3

          Agenore,

           

          Try setting the mergeAlpha parameter of copyPixels to true.

           

          From the ASDoc:

           

          copyPixels

          ()method

          public function copyPixels(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, alphaBitmapData:BitmapData = null, alphaPoint:Point = null, mergeAlpha:Boolean = false):void

          Language Version: ActionScript 3.0
          Runtime Versions: Flash Player 9, AIR 1.0

          Provides a fast routine to perform pixel manipulation       between images with no stretching, rotation, or color effects. This method copies a       rectangular area of a source image to a       rectangular area of the same size at the destination point of the destination        BitmapData object.

          If you include the alphaBitmap and alphaPoint parameters, you can use a secondary        image as an alpha source for the source image. If the source       image has alpha data, both sets of alpha data are used to       composite pixels from the source image to the destination image. The       alphaPoint parameter is the point in the alpha image that       corresponds to the upper-left corner of the source       rectangle. Any pixels outside the intersection of the source       image and alpha image are not copied to the destination image.

           

          The mergeAlpha property controls whether or not the alpha       channel is used when a transparent image is copied onto       another transparent image. To copy       pixels with the alpha channel data, set the mergeAlpha property to true. By default, the mergeAlpha property is       false.

           

          Parameters

          sourceBitmapData:BitmapData — The input bitmap image from which to copy pixels. The source image can be a        different BitmapData instance, or it can refer to the current BitmapData        instance.
          sourceRect:Rectangle — A rectangle that defines the area of the source image to use as input.
          destPoint:Point — The destination point that represents the upper-left corner of the rectangular        area where the new pixels are placed.
          alphaBitmapData:BitmapData (default = null) — A secondary, alpha BitmapData object source.
          alphaPoint:Point (default = null) — The point in the alpha BitmapData object source that corresponds to        the upper-left corner of the sourceRect parameter.
          mergeAlpha:Boolean (default = false) — To use the alpha channel, set the value to        true. To copy pixels with no alpha channel, set the value to        false.

           

           

          Jason