PhotoHolder - Bitmap/BitmapData Problems

Advertisement

Hello guys, how are you?
I'm trying to create an actionscript 3 class that receives an external image, adds it into a movieclip and adjusts it without corrupting the aspect ratio of the image.
I've tried working with BitmapData and Bitmap only, but can not hit the calculations. Can anyone help me?
Thank you,
package
    import flash.display.Bitmap;
          import flash.display.BitmapData;
          import flash.display.DisplayObject;
          import flash.display.Loader;
          import flash.display.MovieClip;
          import flash.display.PixelSnapping;
          import flash.display.Sprite;
          import flash.events.Event;
          import flash.events.IOErrorEvent;
          import flash.geom.Matrix;
          import flash.geom.Rectangle;
          import flash.net.URLRequest;
          import flash.system.LoaderContext;
          public class PhotoHolder extends MovieClip
                    private var _loader:Loader;
                    public function PhotoHolder()
                    public function loadPhoto(urlImg:String):void
                              _loader = new Loader();
                              _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
                              _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
                              _loader.load(new URLRequest(urlImg));
                    private function onError(e:IOErrorEvent):void
                              trace("ERROR!");
                    private function onComplete(e:Event):void
                              var loadedImage:Bitmap = Bitmap(_loader.content);
                              var bmd:BitmapData = new BitmapData(_loader.content.width, _loader.content.height, true);
                              bmd.draw(loadedImage, null);
                              this.holder.addChild(createBitmap(bmd));
                    private function createBitmap(bmd:BitmapData):Bitmap
            var bitmap:Bitmap = new Bitmap(bmd);
            bitmap.smoothing = true;
            setSize(bitmap, bmd.width, bmd.height, this.holder.x, this.holder.y);
            return bitmap;
        private function setSize(target:DisplayObject, contentWidth:Number, contentHeight:Number, targetWidth:Number, targetHeight:Number):void
            var w:Number = targetWidth;
            var h:Number = targetHeight;
            // maintain aspect ratio
            var containerRatio:Number = targetWidth / targetHeight;
            var imageRatio:Number = contentWidth / contentHeight;
            if (containerRatio < imageRatio) h = w / imageRatio;
            else                             w = h * imageRatio;
            target.width = w;
            target.height = h;
            //centre content - this might change based on your setup
            target.x = (targetWidth - w) * .5;
            target.y = (targetHeight -h) * .5;

Advertisement

You´re right! It´s happening, the case is my movieclip. I will think about it. I made fell changes in the class, it´s more easy to read. Now, that is the principal methods:
private function onComplete(e:Event):void
                              var w:Number = this.width;
                              var h:Number = this.height;
                              var loadedImage:Bitmap = Bitmap(_loader.content);
                              _ratio = _loader.content.height / _loader.content.width;
                              this.addChild(resizeIt(loadedImage, w, h));
                    private function resizeIt(bitmap:Bitmap, maxW:Number, maxH:Number):Bitmap
                             if (bitmap.width > maxW)
                                   bitmap.width = maxW;
                                   bitmap.height = bitmap.width * _ratio;
                          if (bitmap.height > maxH)
                                 bitmap.height = maxH;
                                bitmap.width = bitmap.height / _ratio;
                          bitmap.smoothing = true;
                           return bitmap;
But I have one more question:
I'm reducing the size of the image to place it in the container. I'm not using scaleX and scaleY. How do I fill the container without losing image quality?

November 30, -0001

PhotoHolder - Bitmap/BitmapData Problems

Hello guys, how are you? I'm trying to create an actionscript 3 class that receives an external image, adds it into a movieclip and adjusts it without corrupting the aspect ratio of the image. I've tried working with BitmapData and Bitmap only, but c

Bitmap Alpha Problem

Hi; I'm trying to tweak a script I found online to work for my application.  The problem I am having is to make a certain part of the bitmap that is  created by code transparent...but only a certain part of it. The code  has the following: _fire = ne

Selecting Embedded Bitmap Text - Problem

I tried to create a Flash TextField, containing Text with maximum sharpness. So i embedded Verdana Font Size 8 as Bitmap Text, and set sharpness and thickness to my benefits. Now the Text ist displayed cleary, but if you try to select or write into t

Can't do smooth bitmap scale down

Hi, I am working on text warping and below is a part of my code var shape:Shape = new Shape(); shape.graphics.beginBitmapFill(bitmap.bitmapData.clone(), null, false, true); As you can see I put "true" in "smooth" parameter and this per

JPG to BMP conversion problems...

Hi folks, I'm having a bit of trouble. I can't see why BufferedImage img is returning null. Can anyone spot anything?     private void convertImages() {         //Read all the files in a given directory in.  If they are images then convert them.     

Problem with scanning in PS CS6 - scanning process crashes

Hi. Here is my hardware:    Macbook pro 4 GB DDR3 core i5 with plenty of HD space    Epson V700 scanner (6400 dpi scanning capability) My Software:    Adobe CS6 trial What I want to do:    Scan a typical photo that is 6 by 6 inches at 6400 dpi as a b

Problems with rasterisation

Hey guys im new to the forum and come to you for any advice you may have. Basically i have an image(250x300px bitmap), and i want to reduce the size (eg 50% ) of the image so i have been looking at using the live trace. so i have been taking the bitm

I need your help with a code

Hello, Dear All! Could you help me, please: how can i change this code for the gradual dissapear of the first line and not accumulation of lines, because it isn't aesthetically now? var bitmapData = new BitmapData(bWidth,bHeight,true,0x000000); var b

Blur filter + mask

I think a couple people asked about this problem but none of them seemed to get an answer so I am re-posting. This is how blur filter and mask work in code var blur:BlurFilter = new BlurFilter(); blur.blurX = 10; blur.blurY = 10; var mask:Bitmap = ne

How to resize mainstory board in Xcode and iOS simulator ?

I have a problem with Xcode i can't get to resize the main storyboard it shows up like and iPad and in the iOS simulator it shows up big and half the content comes up how do i resize to an iPhone1. Create a BitmapData of the correct size of the full

DiskUtility unable to repair

For a few months now, whenever I run "Verify Disk" on Disk Utility, it's given me a message saying something about BitMap having problems, and telling me to run Repair. Unfortunately, when I run repair, it tell me it is unable to repair the disk

FloodFill Not working with transparent BirmapData, Plz. help...

Hello friends, I hav a movie [instance name : myObject] clip with some pattern design in it. Now i hav converted it to Bitmap to use FloodFill method on Runtime. code in which The floodFill not working: Code: var bitmapData:BitmapData = new BitmapDat

How to resize a photo from CameraUI?

Hi there, i really need som help here. I cant seem understand how to resize an still image taken with the camera. Here are the code so far(also with the upload part). I just need a thumbnail to be uploaded to the server, not the HQ-image. Any ideas?

As2 fullscreen gallery

Hi! I want to create a simple but sweet flash portfolio like:http://www.jeanmalek.com/ That one is a bit over the top for me though, with al the transitions and stuff. I want it to start with a menu with btns calling different xmls showing infullscre

Need help centering different sized images being loaded from a container

stop(); mainArea_mc.visible = false; home_btn.addEventListener(MouseEvent.CLICK, function () { gotoAndStop("Home Template")} ); var totalImages:int = 0; var imageDirectory : String = ""; var currentImage:int = 1; var filePrefix : Strin

Noise problem with moving bitmaps

I'm having trouble with the most recent Flash player (9,0,45,0). When displaying moving bitmaps, the player sometimes shows horizontal noise lines across the image. This doesn't happen on all platforms, but it does happen on my customers', so I've go

Systray icon in AIR strange bitmap problem

Hi there i recently tried to have one of my apps docked to systray instead of taskbar so i've used pretty much the examples floating around and everything went smoothly except the icon itself. I used standard 16x16 png file and it got scrambled looks

Problem with BlendMode.Erase when drawing on bitmap

Hi I have a scenario where I have to draw a UIComponent on a bitmap. UIComponent contains multiple sprites. One of the sprite has a blend mode of ERASE. The uicomponent draws perfectly on the screen, but the erase sprite started appearing when I draw

Bug Problem - Bitmap image invalid 3D Game

Hi, i'm error this is the bitmap invalid at this data on ActionScript. ArgumentError: Error #2015: Invalid BitmapData.           at flash.display::BitmapData/copyPixels()           at Shortcut_Material/comp() Could fix me please this flash player, th

Problem obtaining BitmapData for a canvas via Javascript

Hi, For my web application I have one HTML button, which is outside of flash application shown on the same page. Via Flex application I've declared callback function to be called by Javascript in this way: ExternalInterface.addCallback("cbProcessButt