Недавно мне понадобилось создать вращающуюся BitmapData’у с помощью преобразования через матрицу. При поисках в интернете нашел лишь кривые классы с неправильными тригонометрическими формулами и пришлось написать класс вращения самому.
И вот что вышло:
А вот сам класс:
package asml.utils
{
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.IBitmapDrawable;
import flash.geom.Matrix;
public final class UBitmapData
{
public static function rotation(source:IBitmapDrawable, angle:Number = 0, tWidth:int = 0, tHeight:int = 0):BitmapData{
//IBitmapDrawable - для возможности загонять ресурс типа BitmapData или DisplayObject.
var bitmapData:BitmapData;
var width:int, height:int;
var matrix:Matrix = new Matrix();
var radians:Number;
//Если при повороте меняется размер ресурса
if(tWidth && tHeight){
matrix.scale(tWidth/source['width'], tHeight/source['height']);
width = tWidth;
height = tHeight;
}else{
width = source['width'];
height = source['height'];
}
//центровка и вращение ресурса
if(angle){
if(angle < 0)angle = (360 - angle) % 360;
radians = UMath.radians(angle);
matrix.translate(-width / 2, -height / 2);
matrix.rotate(radians);
matrix.translate(width / 2, height /2 );
//устанавливаю новый разхмер и позицию в зависимости от угла поворота
var w:int, h:int;
if(angle >= 0 && angle <= 90){
/* 0 - 90*/
w = Math.sin(radians)*height + Math.cos(radians)*width;
h = Math.sin(radians)*width + Math.cos(radians)*height;
matrix.tx += (w - width)/2;
matrix.ty += (h - height)/2;
}else if(angle > 90 && angle <= 180){
/* 90 - 180*/
w = Math.sin(radians)*height - Math.cos(radians)*width;
h = Math.sin(radians)*width - Math.cos(radians)*height;
matrix.tx += (w - width)/2;
matrix.ty += (h - height)/2;
}else if(angle > 180 && angle <= 270){
/* 180 - 270*/
w = -(Math.sin(radians)*height + Math.cos(radians)*width);
h = -(Math.sin(radians)*width + Math.cos(radians)*height);
matrix.tx += (w - width)/2;
matrix.ty += (h - height)/2;
}else if(angle > 270 && angle <= 360){
/* 270 - 360*/
w = -(Math.sin(radians)*height - Math.cos(radians)*width);
h = -(Math.sin(radians)*width - Math.cos(radians)*height);
matrix.tx += (w - width)/2;
matrix.ty += (h - height)/2;
}
bitmapData = new BitmapData(w, h, true, 0x000000);
bitmapData.draw(source, matrix);
return bitmapData;
}
bitmapData = new BitmapData(width, height, true, 0);
bitmapData.draw(source, matrix);
return bitmapData;
}
}
}
RSS Feed
Twitter
Posted in 
Здравствуйте, как на Вас подписаться? Я пользуюсь хромом, кнопка RSS не реагирует, ссылка “RSS ленту” выдает страницу полную неформатированного текста…
Извините что вопрос не по теме… пользоваться привык гуглридером…
Google Chrome сам по себе неумеет читать Rss, для этого нужно использовать внешние программы и внести страничку с GoogleReader в закладки.
взято отсюда http://otvety.google.ru/otvety/thread?tid=4a0086a6fb3992a8