Jump to content
Search Community

Image Cloning code

Tito test
Moderator Tag

Recommended Posts

There's been a number of questions on how to clone a imageLoader.getContent, so I thought I'd chuck in a slightly more complete solution so people don't have to waste time doing it.

package com.optricks.Tools 
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.display.DisplayObject;
import flash.geom.Rectangle;

/**
 * ...
 * @author Tito
 */

public class ImageTools 
{
	private static const _myType				:String			= "ImageTools";

	public static function cloneImage(image:DisplayObject)								:DisplayObject
	{
		var bmd			:BitmapData;
		var bitmap		:Bitmap;
		var spr			:Sprite;
		var bounds		:Rectangle = image.getBounds(image);

		bmd				= new BitmapData(int(bounds.width + 0.5), int(bounds.height + 0.5), true, 0x0);
		bmd.draw(image, new Matrix(1, 0, 0, 1, -bounds.x, -bounds.y));

		bitmap			= new Bitmap(bmd, "auto", true);
		bitmap.x		= bounds.x;
		bitmap.y		= bounds.y;

		spr				= new Sprite();
		spr.addChild(bitmap);
		return spr;
	}

}}

 

Hope this saves you 20 minutes

Link to comment
Share on other sites

  • 2 weeks later...

Ok I had some thumb resizing going on that I didn't realize - so now the bitmap thumbs aren't too bad.

 

But I'd still like to send over a COPY of the SWF to the subject, rather than the thumbnail SWF - otherwise the user can only put 1 of those items on the screen, 1 time - they can't ever access that item again without reloading all of the thumbs. So I need to find a way to create a duplicate of the ContentDisplay object on the fly, whenever the user clicks on it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...