bitmapData scale bug


hi,
i importing movie external image, once loaded make bitmapdata
object of it, scale half , attach dynamically created
mc (i know procedure doesn't make sense, part of
larger procedure won't describe in here).
anyway, newly created mc displays image correctly, actual
size same of original image, not half of it.

put code new movie , check 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 line around mc see boundaries
_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); // outputs 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); // should outputs half width of
original image
_level0.createemptymovieclip("new_mc",2);
new_mc.attachbitmap(_bmp,1);
// adding line around new mc see boundaries
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 new mc near original mc can
compared
new_mc._x = _mc._width+20;
trace("new: "+new_mc._width); // should outputs half
width of original image
}

_mcl.addlistener(_obj);
_mcl.loadclip("imagefile.gif",_mc)

why doesn't new mc's size actuall size of image
holding???

thanks,
erez


this expected result, not bug @ all.

you creating bitmapdata object set dimensions,
independent of content draw object. using
matrix transform draw object, *not*
object itself. more apparent if give original bitmapdata
object visible background:

var _bmp:bitmapdata = new bitmapdata(_mc._width, _mc._height, false,
0xff0000);

so, solution create bitmapdata object @ right size,
proceed were. btw, need check line:

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

that should be:

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

so, script 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 line around mc see boundaries
_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);
// outputs 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);
// should outputs half width of original image
_level0.createemptymovieclip("new_mc", 2);
new_mc.attachbitmap(_bmp, 1);
// adding line around new mc see boundaries
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 new mc near original mc can compared
new_mc._x = _mc._width+20;
trace("new: "+new_mc._width);
// should outputs half width of original image
};
_mcl.addlistener(_obj);
_mcl.loadclip("skate.jpg", _mc);



hth

pete



--
-------------------------------
remove '_spamkiller_' mail
-------------------------------




More discussions in ActionScript 1 and 2


adobe

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support