Bitmapdata scale9

Asked by chris

Hello I am wanting to use a scale9grid method to resize images. Is this part of the nme api not yet implemented in jeash?

For example this works with flash and cpp but not the html5;

public static function scale9Bitmap (w:Int,h:Int,_scale9Grid:Rectangle,originalBitmap:BitmapData):BitmapData {
  var bmpData:BitmapData = new BitmapData (w,h,true,0x00000000);

  var rows:Array<Float> = [0,_scale9Grid.top,_scale9Grid.bottom,originalBitmap.height] ;
  var cols:Array<Float> = [0,_scale9Grid.left,_scale9Grid.right,originalBitmap.width];

  var dRows:Array<Float> = [0,_scale9Grid.top,h - (originalBitmap.height - _scale9Grid.bottom),h];
  var dCols:Array<Float> = [0,_scale9Grid.left,w - (originalBitmap.width - _scale9Grid.right),w];

  var origin:Rectangle;
  var draw:Rectangle;
  var mat:Matrix = new Matrix ();

  var cx:Int = 0;
  while (cx < 3) {

   var cy:Int = 0;
   while (cy < 3) {
    origin = new Rectangle (cols[cx],rows[cy],cols[cx + 1] - cols[cx],rows[cy + 1] - rows[cy]);
    draw = new Rectangle (dCols[cx],dRows[cy],dCols[cx + 1] - dCols[cx],dRows[cy + 1] - dRows[cy]);
    mat.identity ();
    mat.a = draw.width / origin.width;
    mat.d = draw.height / origin.height;
    mat.tx = draw.x - origin.x * mat.a;
    mat.ty = draw.y - origin.y * mat.d;
    bmpData.draw (originalBitmap,mat,null,null,draw,true);
    cy ++;

   }

   cx ++;
  }

  return bmpData;
 }

Question information

Language:
English Edit question
Status:
Open
For:
jeash Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
chris (impaler777) said :
#1

It seems that the bmpData.draw is the thing not working, other use case not working here;
http://www.haxenme.org/community/forums/programming-with-haxe/scaling-bitmapdata-html5-target/

Revision history for this message
Niel Drummond (niel-drummond) said :
#2

Many of the additional parameters to BitmapData.draw could be implemented, but because there is no equivalent native browser feature, it would have to be written in software. A javascript implementation is likely to slow the browser so much that it crashes if the user calls it every frame. Nevertheless, I can test it again to see if there's some trick I can use with canvas' methods to get it to work. Any ideas would be very welcome.

Can you help with this problem?

Provide an answer of your own, or ask chris for more information if necessary.

To post a message you must log in.