AS3 bitmap mosaic class

Posted on

This class will allow you to create a pixellated copy of any display object.

It allows for varying pixel sizes and caching of rendered pixels so you don’t have to redraw them every time.

mosaic

Usage is as follows:

var myMoz:Mosaic = new Mosaic(yourDisplayObj:DisplayObject, pixelSize:uint, useCache:Boolean);
addChild(myMoz);

or

var myMoz:Mosaic = new Mosaic(yourDisplayObj);
myMoz.pixelSize = 10;
myMoz.render();

Give it a try and let me know what you think.

41 thoughts on “AS3 bitmap mosaic class

  1. Pingback: Actionscript Classes » Bitmap Mosaic

  2. Pingback: combinecreative.com » Blog Archive » AS3 bitmap mosaic class

  3. Hello,

    Nice job but i have a problem trying to use it in Full Browser. I put a mosaic image in background (full browser), and the image is supposed to resize when i resize my window. It works well but the mosaic image sometimes draw horizontal and vertcal outlines around the mosaics…

    Is it normal ? Is it possible to fix it ?

    Thank You !

    Cédric from Montreal…

    [Cedric, your stage scale mode is probably set to EXACT_FIT which is the default. To fix this you should set it to NO_SCALE. Of course after doing that you’d need to listen for a RESIZE event from the Stage and do all your other element’s resizing manually through code. Hope this helps – JK]

  4. hey there!
    I’m trying to use this class but I get this error:

    Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.

    Any help?
    Cheers!

  5. Hi julian,

    Nice work, though I thought to change it a bit.
    You can have a look here.
    http://gfxcomplex.com/MosaicFilter.zip

    I like the use of graphics better, because you can use the clear() method to clean old graphics faster then you can using removeChild() and creating extra vars for holding pixels.

    That and I added most stander compliant coding. I would not recommend using public vars ever.

    PS: I run the AS3 User group in st.Louis, you should come to visit. Your a good code, but I think you could use some help on standers.

    • One thing missing now though is the caching I had built in. That way once you draw a 10px Mosaic, you can access it again at any time without redrawing it.

  6. The BitmapData.draw() only happens once. Thats the slowest method of the class.

    I have got this to work with video at 3 pixel size at 60fps with no problem

    this is really fast, the only thing I could think to make this work faster would be to use a Vector class.

    I guess I would need to see a real world use where I would need the cashed shape.

  7. I Just updated the zip again. this Time I did it with pixel bender. super fast!
    Note: this only work with flash 10.

    If you don’t have flash 10, I could show you how to use flash develop with the flex 4 sdk to compile flash 10 for free.

  8. Pingback: Mosaic effect | Aleksey Matveev blog

  9. Pingback: Mosaic Class, different tests at Helpful stuff

  10. Hi again.

    I actually found the answer to my own question about the transparent png.

    In the Mosaic.as I changed the getPixel function to getPixel32.

    var color:uint = bmd.getPixel(colorX , colorY);
    to
    var color:uint = bmd.getPixel32(colorX , colorY);

    Let me know if there is a problem with this.

  11. Pingback: 8 Classical ActionScript Classes About BitMap - Ntt.cc

  12. Pingback: 8?bitmap??? | ??-????

  13. Pingback: RIACOOL'BLOG | 8?bitmap???

  14. Pingback: AS???????? « Deepin 3000

  15. Pingback: AS???????? « Deepin 3000

  16. Pingback: 8 Classical ActionScript Classes About BitMap | Adobe Show Center

  17. Pingback: AS???????? ? Ase7en’Blog

  18. Pingback: 8?bitmap??? « echo "RenYuan's Blog"

  19. Pingback: AS3?????????????? | AS3??

  20. Pingback: AS???????? | ???????

  21. Pingback: as518.com

  22. Pingback: ????? » AS????????

  23. Pingback: 8?bitmap??? - ChinemitBlog

  24. Pingback: AS???????? ? ???????

  25. @Josh, Julian

    Great class, very nice work – short, sweet and effective!

    One question, though – the pixelation happens from top-left (0,0). Any chance of pointers to get it working from another position, say perhaps the centre (but ideally any co-ordinate)?

    thanks

  26. Pingback: ??? » Blog Archive » ??bitmap???

  27. This class is awesome! Thanks so much for sharing.

    I did ran into a problem. The Mosaic filter works fine when running locally, but as soon as I place the swf on a webserver, the Flash movie halts at the moment of creating the class instance. Any clue what goes wrong here?

  28. Good job on that class.

    Troubles I got with it, my movieclip, which was drawn from, was centered – so all content from the left side of the pivot point wasn rendered.
    Just replace the first 2 lines of the constructor with this to remove this effect:

    bmd = new BitmapData(srcDispObj.width, srcDispObj.height);
    var m:Matrix = new Matrix();
    m.translate(-srcDispObj.getRect(srcDispObj).x, -srcDispObj.getRect(srcDispObj).y);
    bmd.draw(srcDispObj, m);

  29. Pingback: AS程序员实用工具类 | 好多钱软件

  30. Pingback: AS开发工具集(长期更新) | Bindiry's Blog

  31. Pingback: flash实用工具类+开源包收藏 - HTML/CSS - 开发者第2276686个问答

  32. Pingback: flash实用工具类+开源包收藏 - Ase7en’Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*