pet-theory
09-21-2006, 07:36 PM
I'd like to scale a bitmap that is never seen but used in order to create an effect.
Basically, I'd like noise, but a more pixelated, blockier noise than a per-pixel noise. So I need to noise-up a bitmapdata, then magnify it.
Well, bitmapData's aren't displayObjects, so they don't have scaleX and scaleY properties. And their width and height propertes are read-only. So how to scale up a texture bitmap, then?
All I can come up with so far is to try to get the bitmapData to draw part of itself (with a clipping matrix half its size, and a transform matrix that doubles that).
package
{
import flash.geom.*;
import flash.display.*;
//
public class Test extends Sprite
{
public function Test() {
//make bitmapdata
var bdata=new BitmapData(100, 100)
bdata.noise(Math.random()*1000, 0, 255, 1)
//make matrix
var mtr=new Matrix()
var scaleFactor=2;
mtr.scale(scaleFactor,scaleFactor);
//apply it to the bitmapdata
bdata.draw(bdata, mtr, null, null, new Rectangle(0,0, bdata.width/scaleFactor, bdata.height/scaleFactor));
//display it
var bitmap=new Bitmap(bdata)
bitmap.x=200;
bitmap.y=200;
addChild(bitmap);
}
}
}
The result some weird distortion that I can't explain.
I suppose I could blit it, scale it, and draw it, but I'm sure there is an easier way.
Thanks.
Basically, I'd like noise, but a more pixelated, blockier noise than a per-pixel noise. So I need to noise-up a bitmapdata, then magnify it.
Well, bitmapData's aren't displayObjects, so they don't have scaleX and scaleY properties. And their width and height propertes are read-only. So how to scale up a texture bitmap, then?
All I can come up with so far is to try to get the bitmapData to draw part of itself (with a clipping matrix half its size, and a transform matrix that doubles that).
package
{
import flash.geom.*;
import flash.display.*;
//
public class Test extends Sprite
{
public function Test() {
//make bitmapdata
var bdata=new BitmapData(100, 100)
bdata.noise(Math.random()*1000, 0, 255, 1)
//make matrix
var mtr=new Matrix()
var scaleFactor=2;
mtr.scale(scaleFactor,scaleFactor);
//apply it to the bitmapdata
bdata.draw(bdata, mtr, null, null, new Rectangle(0,0, bdata.width/scaleFactor, bdata.height/scaleFactor));
//display it
var bitmap=new Bitmap(bdata)
bitmap.x=200;
bitmap.y=200;
addChild(bitmap);
}
}
}
The result some weird distortion that I can't explain.
I suppose I could blit it, scale it, and draw it, but I'm sure there is an easier way.
Thanks.