3 Replies Latest reply on Aug 23, 2006 8:04 AM by Newsgroup_User

    bitmapData scale bug

    Level 7
      hi,
      i importing into my movie an external image, once loaded make a bitmapData
      object of it, scale it by half and then attach it to a dynamically created
      MC (i know this procedure doesn't make too much sense, but its a part of a
      larger procedure which i won't describe in here).
      anyway, the newly created MC displays the image correctly, but its actual
      size is the same of the original image, not half of it.

      put this code into a new movie and check it for yourself:

      import flash.display.BitmapData;
      import flash.geom.Matrix;

      _level0.createEmptyMovieClip("_mc",1);
      var _mcl:MovieClipLoader = new MovieClipLoader();
      var _obj:Object = new Object();

      _obj.onLoadInit = function() {
      // adding a line around the MC to see its boundaries clearly
      _mc.lineStyle(1,0x0000ff);
      _mc.moveTo(-1,-1);
      _mc.lineTo(_mc._width,-1);
      _mc.lineTo(_mc._width,_mc._height);
      _mc.lineTo(-1,_mc._height);
      _mc.lineTo(-1,-1);
      trace("mc: "+_mc._width); // this outputs the original image's width
      var _bmp:BitmapData = new BitmapData(_mc._width,_mc._height);
      var _matrix:Matrix = new Matrix();
      _matrix.scale(0.5,0.5);
      _bmp.draw(_mc,_matrix);
      trace("bmp: "+_bmp.width); // this should outputs half the width of the
      original image
      _level0.createEmptyMovieClip("new_mc",2);
      new_mc.attachBitmap(_bmp,1);
      // adding a line around the new MC to see its boundaries clearly
      new_mc.lineStyle(1,0x00ff00);
      new_mc.moveTo(-1,-1);
      new_mc.lineTo(new_mc._width,-1);
      new_mc.lineTo(new_mc._width,_mc._height);
      new_mc.lineTo(-1,new_mc._height);
      new_mc.lineTo(-1,-1);
      // placing the new MC near the original MC so they can be easily
      compared
      new_mc._x = _mc._width+20;
      trace("new: "+new_mc._width); // this should also outputs half the
      width of the original image
      }

      _mcl.addListener(_obj);
      _mcl.loadClip("imageFile.gif",_mc)

      why doesn't the new MC's size is the actuall size of the image its
      holding???

      thanks,
      eRez


        • 1. Re: bitmapData scale bug
          Level 7
          This is the expected result, not a bug at all.

          You are creating your BitmapData object with set dimensions, which are
          independent of any content you draw into that object. You are using your
          matrix to transform what you then draw into that object, but *not* the
          object itself. This is more apparent if you give your original BitmapData
          object a visible background:

          var _bmp:BitmapData = new BitmapData(_mc._width, _mc._height, false,
          0xFF0000);

          So, the solution is to create the BitmapData object at the right size, then
          proceed as you were. BTW, you also need to check this line:

          new_mc.lineTo(new_mc._width,_mc._height);

          That should be:

          new_mc.lineTo(new_mc._width, new_mc._height);

          So, your script would look something like:

          import flash.display.BitmapData;
          import flash.geom.Matrix;
          _level0.createEmptyMovieClip("_mc", 1);
          var _mcl:MovieClipLoader = new MovieClipLoader();
          var _obj:Object = new Object();
          _obj.onLoadInit = function() {
          // adding a line around the MC to see its boundaries clearly
          _mc.lineStyle(1, 0x0000ff);
          _mc.moveTo(-1, -1);
          _mc.lineTo(_mc._width, -1);
          _mc.lineTo(_mc._width, _mc._height);
          _mc.lineTo(-1, _mc._height);
          _mc.lineTo(-1, -1);
          trace("mc w: "+_mc._width);
          trace("mc h: "+_mc._height);
          // this outputs the original image's width
          var _bmp:BitmapData = new BitmapData(_mc._width/2, _mc._height/2);
          var _matrix:Matrix = new Matrix();
          _matrix.scale(0.5, 0.5);
          _bmp.draw(_mc, _matrix);
          trace("bmp w: "+_bmp.width);
          trace("bmp h: "+_bmp.height);
          // this should outputs half the width of the original image
          _level0.createEmptyMovieClip("new_mc", 2);
          new_mc.attachBitmap(_bmp, 1);
          // adding a line around the new MC to see its boundaries clearly
          new_mc.lineStyle(1, 0x00ff00);
          new_mc.moveTo(-1, -1);
          new_mc.lineTo(new_mc._width, -1);
          new_mc.lineTo(new_mc._width, new_mc._height);
          new_mc.lineTo(-1, new_mc._height);
          new_mc.lineTo(-1, -1);
          // placing the new MC near the original MC so they can be easily compared
          new_mc._x = _mc._width+20;
          trace("new: "+new_mc._width);
          // this should also outputs half the width of the original image
          };
          _mcl.addListener(_obj);
          _mcl.loadClip("skate.jpg", _mc);



          HTH

          Pete



          --
          -------------------------------
          Remove '_spamkiller_' to mail
          -------------------------------


          • 3. You're welcome ;)
            Level 7


            --
            -------------------------------
            Remove '_spamkiller_' to mail
            -------------------------------

            "eRez" <ebaram@hotmail.com> wrote in message
            news:echk46$qd3$1@forums.macromedia.com...
            >
            >