Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7032569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:57:08+00:00 2026-05-28T00:57:08+00:00

To flip an image around the center i am using this piece of code:

  • 0

To flip an image around the center i am using this piece of code:

        // Calculate offset
        var offsetWidth:Number = image.contentWidth/2.0;
        var offsetHeight:Number =  image.contentHeight/2.0;
        // Perform flip
        var matrix:Matrix = new Matrix();
        matrix.translate(-offsetWidth, -offsetHeight);
        if(direction=="HORIZONTAL"){
            matrix.scale(-1, 1);
        }else if(direction=="VERTICAL"){
            matrix.scale(1,-1)
        }
        matrix.translate(+offsetWidth, +offsetHeight);
        matrix.concat(image.transform.matrix);
        image.transform.matrix = matrix.clone();

which works fine.But my problem is when i try to get the BitmapData from the image like this:

        var bitmapData:BitmapData = new BitmapData(image.width,image.height); 
        bitmapData.draw(image);

and use the bitmapData as source for another image,no image is displayed.Broken image icon appears.
Also i am rotating the image around center and using similar code as mentioned below and its working fine and i am able to copy the bitmapdata to another image..here’s the code for reference:

   var matrix:Matrix = new Matrix(); 
   matrix.rotate(Math.PI/2); 
   matrix.tx = img.content.height; 
   var bd:BitmapData = new BitmapData(img.content.height, img.content.width);   
   bd.draw(img.content, matrix);

Please help regarding the same.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:57:09+00:00Added an answer on May 28, 2026 at 12:57 am

    Answer is in the question.

    In the second case you are using matrix

    bd.draw(img.content, matrix);
    

    Similarly do for the flip

    bitmapData.draw(image, matrix);
    

    EDIT:

    Calculation of the translation for the matrix in flipping is not correct. Both the translation on X and Y are needed only when you flip horizontally and vertically.
    Please find the code below in which it is working.

    package
    {
        import flash.display.Bitmap;
        import flash.display.BitmapData;
        import flash.display.Sprite;
        import flash.display.StageScaleMode;
        import flash.geom.Matrix;
        import flash.geom.Rectangle;
    
        [SWF(width="640", height="480")]
    
        public class FlipRotate extends Sprite
        {
            [Embed(source="away3d.jpg")]
            private var Pic:Class;
    
    
            public function FlipRotate()
            {
                super();
    
                stage.scaleMode = StageScaleMode.NO_SCALE;
    
    
                var sourceImage:Bitmap;
                var targetImage:Bitmap;
    
                sourceImage = new Pic();
    
                //flip(sourceImage, "BOTH");
                flip(sourceImage, "VERTICAL");
                //flip(sourceImage, "BOTH");
    
                rotate(sourceImage, Math.PI/3);
    
    
    
                targetImage = new Bitmap();
    
                /* Get the current bounds of source image to calculate the dimenstion of new image
                 Apply translation to bring the content outside into view in new image */
                var bounds:Rectangle = sourceImage.getBounds(this);
                var matrix:Matrix = sourceImage.transform.matrix;
                matrix.translate(-bounds.x, -bounds.y);
    
                /* Draw in new image applying translated matrix of source imgae */
                targetImage.bitmapData = new BitmapData(bounds.width, bounds.height);
                targetImage.bitmapData.draw(sourceImage, matrix);
    
                /* Add new image and postion at the center of stage */
                addChild(targetImage);
                targetImage.x = (stage.stageWidth-targetImage.width)/2;
                targetImage.y = (stage.stageHeight-targetImage.height)/2;
    
            }
    
            public function flip(image:Bitmap, direction:String):void{
    
                var matrix:Matrix = image.transform.matrix;
    
                if(direction=="HORIZONTAL"){
                    matrix.scale(-1, 1);
                    matrix.translate(image.width, 0);
                }else if(direction=="VERTICAL"){
                    matrix.scale(1,-1);
                    matrix.translate(0, image.height);
                }else if(direction == "BOTH"){
                    matrix.scale(-1,-1);
                    matrix.translate(image.width, image.height);
                }
    
                image.transform.matrix = matrix;
    
            }   
    
            public function rotate(image:Bitmap, angle:Number):void{
    
                var matrix:Matrix = image.transform.matrix;
    
                matrix.translate(-image.width/2, -image.height/2);
                matrix.rotate(angle); 
                matrix.translate(image.width/2, image.height/2);
    
                image.transform.matrix = matrix;
    
            }   
    
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a library/simple way to flip an image? Flip image like this: AABBCC
I use this class to crop, resize my image: http://www.phpclasses.org/package/4268-PHP-Resize-crop-rotate-flip-flop-and-grey-images.html It uses GD. The
I am loading an image using the OpenEXR library. This works fine, except the
I can flip my view by doing something like this: image.transform = CGAffineTransformMakeScale(-1, 1);
I've got a set of <canvas> elements that I am flipping around using flip!
I need to flip an image so that a character faces in the right
I am using the flip animation to animate between two views in my viewcontroller.
I'm trying to flip between two views. That's easy, the code is below, but
I'm trying to flip a bit field in SQL Server using an update query,
I want to include Flip view in my project. I made it like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.