Tilt Shift Photography


(Jason Pickering) #1

Hey guys, so I have been wondering about this. Its fairly easy to fake tilt shift photography in GIMP or photoshop, would it be possible to fake it in Flashpunk? the way its faked in Gimp is making a duplicate of the scene bluring it and then adding a gradient mask, but I am wondering if the Blur filter in Flash might work well for this. can you control it with a gradient?


(fedyfausto) #2

i think you can use the metod GetBuffer


(Elliot Colp) #3

You should be able to do something like that, yeah. Here’s how I would handle it (hopefully this code works!):

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.BlurFilter;
import flash.geom.Point;
import net.flashpunk.graphics.Image;

public class TiltShift extends Entity
{
    [Embed(source = 'gradient.png')]
    static private const GRADIENT:Class;
    
    [Embed(source = 'image.png')]
    static private const TILTIMAGE:Class;
    
    public function BackgroundBlur() 
    {
        var p:Point = new Point;
        
        // Create the bitmaps
        var imageBmp:Bitmap = new TILTIMAGE;
        var imageData:BitmapData = imageBmp.bitmapData;
        var gradientBmp:Bitmap = new GRADIENT;
        
        // Create an empty layer
        var blurData:BitmapData = new BitmapData(imageBmp.width, imageBmp.height,
                                                 true, 0x00000000);
        
        // Put the blurred image in the empty layer
        var filter:BlurFilter = new BlurFilter(5, 5);
        blurData.applyFilter(imageData, imageData.rect, new Point, filter);
        
        // Apply the gradient and copy over the blurred layer
        imageData.copyPixels(blurData, imageData.rect, new Point, gradientBmp.bitmapData,
                             new Point, true);
        
        // Store the bitmap data in the image
        graphic = new Image(imageData);
    }
}