Open a disk image file and crop it to an Image control

Hi Folks,
I am trying to allow my users (in a browser) to select/open a disk file (image type) so that they can see it and then save it to the server.  I can use the FileReference object just fine, and load its 'result' directly into a MX:Image control.  However, before I do that I would like to crop the selected imaged to a square shape.  I'd also like to resize the image down, but that will come later, once I get the cropping working.
I am essentially taking the FileReference result bytearray and converting that to a BitmapData object.  Then, I 'extract' a square of data from that BitmapData object into a new BitmapData object.  Then I need to get *that* BitmapData object into the mx:image control.  I tried using a Bitmap to do so, however the resulting mx:image, while 'sized' correctly, displays as a blank white region.  All along, the variables seem to be 'full' of data and seem to have properly set attributes.  I've looked up quite a few sites that demonstrate cropping, and copying images, but they always start out with 'pre-loaded' images.  I have modeled my code after theirs, where appropriate.
Here is my code:
          //this gets called when the user clicks a button to 'look for a disk file'
            private function setPhoto():void
                //create the FileReference instance
                _fileRef = new FileReference();
                _fileRef.addEventListener(Event.SELECT, onFileSelected);
                //listen for the file has been opened
                _fileRef.addEventListener(Event.COMPLETE, onFileLoaded);
                var arr:Array = [];
                arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));
                _fileRef.browse(arr); //then let go and let the event handlers deal with the result...
            private function onFileSelected(evt:Event):void
                _fileRef.load(); //the result of the 'load' will be handled by the 'complete' handler
            private function onFileLoaded(evt:Event):void
                var tempLoader:Loader = new Loader();
                tempLoader.loadBytes(_fileRef.data);
                tempLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
                //imgPhoto.source = _fileRef.data;  //this would work just fine, though, it wouldn't be cropped
            private function onLoaderComplete(event:Event):void
                var loaderInfo:LoaderInfo = LoaderInfo(event.target);
                var loadBD:BitmapData = new BitmapData(loaderInfo.width,loaderInfo.height);
                //ok, now that we have the 'original' file in the bitmap data, we can crop it and then later resize it
                //so, we need a 'square' of image cropped out of the original
                //so...first we get a square of the 'full size' image
                //if the image is taller than wide, we will take a square as wide as the image, and as tall as it is wide, starting 5% down from the top
                //if the image is wider than tall, we will take a square as tall as the image, and as wide as it is tall, from the horizontal middle
                var curW:int = loadBD.width;
                var curH:int = loadBD.height;
                var cropX:int = 0;
                var cropY:int = 0;
                var cropW:int = curW;
                var cropH:int = curH;
                var needCrop:Boolean = true; //default is to crop
                var croppedBD:BitmapData;
                if (curH > curW)
                    cropY = Math.round(curH * .05); //start at 5% down
                    cropH = cropW;
                else if (curW > curH)
                    cropX = Math.round(curW/2) - Math.round(curH/2); //start at the middle, go 'back' by half the height
                    cropW = cropH;
                else
                    needCrop = false; //it's already a square!  nothing to do (aside from the resize)
                if (needCrop)
                    croppedBD = new BitmapData(cropW, cropH); //at this point it is 'empty', so fill it up
                    var fillPoint:Point = new Point(0,0); //since we're gonna fill into the top, left pixel on down and over
                    var fillRect:Rectangle = new Rectangle(cropX,cropY,cropW,cropH);
                    croppedBD.copyPixels(loadBD,fillRect,fillPoint);
                else
                    croppedBD = loadBD;
                imgPhoto.source = new Bitmap(croppedBD);  //this produces a properly sized, but blank-white image
And here is the mxml for the image:
<mx:Image id="imgPhoto" x="40" y="126" maxWidth="200" maxHeight="200" />
Thanks!
-David

Hi,
You were close to the solution.
In "onLoaderComplete(event:Event):void", at the begining you create a BitmapData called "loadBD", you just forgot to fill it with the content from the loaderInfo.
private function onLoaderComplete(event:Event):void {
     var loaderInfo:LoaderInfo = LoaderInfo(event.target);
     var loadBD:BitmapData = new BitmapData(loaderInfo.width,loaderInfo.height);
     loadBD.draw(loaderInfo.content);
Kind regards,
Mich

Similar Messages

  • How to open a pdf file and then attach it with images

    I am new to Indesign Server.
    I'm currently working on a pdf.
    I have a white blank pdf template.
    that I want to attach/glue it with images.
    How to open a pdf file and then attach it with images.
    Please, help me.
    Thanks.

    First step would be to make yourself familiar with InDesign desktop version.
    Whatever you intend to achieve, do it there manually. (see regular app docs or forums)
    Then try to automate your steps with scripting (see scripting docs or forum)
    If you can do it with a script in the desktop version, that script will likely also run in ID Server. (see server forum).
    If you can specify missing features not achievable thru scripting or manual use, reconsider to write a plugin (this forum).
    A seasoned C++ programmer will need a few months to learn the basics, wade thru tons of documentation etc. Alternatively consider to hire a consultant to do the development work for you.
    Dirk

  • PSE13 repeatedly crashing when opening more than one file at a time to layer images. [was: Feeling very frustrated.]

    Just bought Photoshop Elements 13.  I have a Macbook Pro that meets all the requirements.  I have installed and reinstalled the program but it just keeps crashing.  The program will load, when I choose the expert tab and try to open more than one file at a time to layer images it just crashes and says "Photoshop Elements has closed unexpectedly" Can anyone help me please?

    mikeobe wrote:
    OK, kinda slooow here, I hope I'm not trying your patience!? If I understand you correctly, install dummy drivers and then the drivers that came with my printer, Designating NO default printer! Then when I need to use the printer I will have to declare which one each and every time?
    Or, just intall by new printer but do not Delcare it as the Default printer, I guess in this instance there would be NO default printer?
    You may not even have the problem!
    Have you installed the new printer yet?
    There are many more people who don't see it happen than those who do.
    PS: there is always a default printer.

  • I bought a canon EOS Rebel T5i. It came with photoshop elements 11.  PS won't open my C2 raw files and says my camera isn't supported by the software I have downloaded 7.4 dng converter and I still can't open the files.  What do I need to do?

    I bought a canon EOS Rebel T5i. It came with photoshop elements 11.  PS won't open my C2 raw files and says my camera isn't supported by the software I have downloaded 7.4 dng converter and I still can't open the files.  What do I need to do?

    You need camera raw 8.4 for your camera, if it’s Digital Rebel T5 EOS 1200D EOS Kiss X70. It is not compatible with PSE11; so it’s a bit odd if that software was bundled with the camera except that it will work with jpegs. I suggest you download and install the free Adobe DNG converter to convert your CR2 files to the Adobe universal Raw format and the DNG files will editable in PSE11(keep your originals as backups and for use in the camera manufactures software)
    Mac download (.dmg file) click here DNG Converter 8.4
    You can convert a whole folder of raw images in one click. See this quick video tutorial:
    You Tube click here for DNG Converter tutorial

  • Why when i connect my phone to my laptop do my recent photos load as image files and not jpeg

    why is it that when i connect my phone to my laptop my recent photos load
    as image files and not jpeg as they used to.Is this another issue with ios 8

    Thank you. I did that and made sure my phone was open to the camera roll. I was able to locate the import command and the photos appeared. Thanks so much!

  • IO - Read two image files and put them into one file

    Hi,
    i have 3 files in all. The two image files and one text file. I need to place the image in the first image file, followed by text in the text file and then the image in the second image file, into one file.
    Can anyone tell me how do i go about doing this ?
    i tried using fileinputstream and fileoutputstream, which works fine if all the 3 files have text but when the first and the third file have image, the code doesn't give any error but the result file displays only the image from the first file and nothing else.
    i am running short of time and need to do this really soon.
    if anyone has done anything like this. please let me know,
    thanx,
    poonam

    One approach would be to programmatcally create a single zip/jar file from the three input files. You can use the java.util.zip and java.util.jar packages for this purpose.
    The other apprach would be to create a single image by drawing images and text strings on a BufferedImage object.
    I think the first approach is preferable because you can easily extract the individual files from the zip/jar file

  • I just bought a new dell quad core 5i and HAVE DOWNLOADED THE TRIAL VERSION OF PHOTO SHOP - its Slow to open up a small file and equally as slow to print why?

    HELP I just bought a new dell quad core 5i and HAVE DOWNLOADED THE TRIAL VERSION OF PHOTO SHOP - its Slow to open up a small file and equally as slow to print why?

    Use Photoshop menu Help>system Info... use its copy button and paste that info in an append here.
    Supply pertinent information for quicker answers
    The more information you supply about your situation, the better equipped other community members will be to answer. Consider including the following in your question:
    Adobe product and version number
    Operating system and version number
    The full text of any error message(s)
    What you were doing when the problem occurred
    Screenshots of the problem
    Computer hardware, such as CPU; GPU; amount of RAM; etc.

  • Lightroom 3 Beta-Image Rotate and Crop Tool

    Good Morning Adobe,
    First of all let me say Lightroom 3 is fantastic! I do have a couple of suggestions that might make the image editing more efficient. I find that I use the image rotate and crop tools frequently and think that possibly locating these 2 features below the image in the tool bar with the loupe view/zoom fit/before and after will allow the user to edit the images more efficiantly.
    I believe that this is an incredible program and can't wait to see the finished product!
    I will offer more suggestions as they evolve.
    Thank you Adobe! You are the BEST!
    D.A.    

    Thank you...I discovered this answer online from another post last night and tried it.  (Since I didn't re-size the thumbnails, I wasn't aware that you could do this.)  After re-starting Lightroom and my computer, the crop issue corrected itself.  Thank you very much for your response.  It worked!

  • Submitting an image file for indexing generates the tokens "IMAGE" and "1"

    This is a problem because the user is able to submit any file through a web interface, and we want to determine when there is zero output from the indexing process so we can warn the user that the file they submitted has no indexable content.
    I'd rather keep the detection algorithm simple: currently it checks to see whether any tokens were indexed for the record the user just edited, and IF there were NO tokens, the user is warned that the file they submitted contains no indexable words. But if ctxhx.exe generates the string "Image 1" when someone gives it (for example) a jpeg file, that's not going to work.
    So my questions are these: How do I prevent ctxhx from generating any tokens when someone gives it an image file? And if that's not possible, how can I include logic in a batch file to detect an image file and prevent ctxhx from handling it? (Since the files are renamed without extensions when indexed, I can't determine file type from extensions). I know there's a command-line program called TestForPDF.exe, which I found at http://www.oracle.com/technology/products/text/htdocs/altfilters.htm; is there a similar program (perhaps TestForImage.exe), or instructions for creating such a program?

    I finally resorted to using the "format column" feature of the context index. The code in my front-end looks at the extension of the file submitted by the user, and sets the value of the format column to "IGNORE" before it tries to resync the index. It seems a bit kludgy, but it works.

  • I have a MacBook Pro (purchased in 2011) with OS X Lion 10.7.4.  I'm using Microsoft Office 2011 and cannot open older PowerPoint Files (non .pptx). It will always open the same .pptx file and then the machine hangs up and just keeps spinning.

    I have a MacBook Pro (purchased in 2011) with OS X Lion 10.7.4.  I'm using Microsoft Office 2011 and cannot open older PowerPoint Files (non .pptx). It will always open the same .pptx file and then the machine hangs up and just keeps spinning.

    Thank you - that all makes sense. It is, indeed, exactly what I did when I upgraded.
    I'm also writing this on the machine that crashed a few minutes ago (I posted the crash in another thread). I got back with a 'safe boot' - as I have done a few times before.
    I've also de-installed little snitch (and then done a safe-boot & then re-boot ) since that seemed involved. I de-installed Adobe flash, since that seemed to be a problem - I then re-installed the later, apparently fixed, flash. The most recent crashes don't seeme to have a problem with flash any more.
    I've posted the various ( generally different ) crashes. I also posted a summary of the similar lines that turn up in most of the crashes.
    Unfortuantely, I'm actually trying to use the machine to meet some urgent deadlines and all this is not making it at all easy.
    I had had great hopes for 10.7.2 - I thought that the crashes must be pretty common, so would have a common aetiology. There do seem to have been some fundamental changes to the file sytem and to the video interface (that seems to cause problems to brand new iMacs as well as to my 2009 iMac).

  • I am trying to batch convert cr2 to jpg. in bridge i go tools ps image processor and it returns a message "Image Processor.jsx could not be found." I updated cc to no avail. i am on mac 10.7.5

    I am trying to batch convert cr2 to jpg. in bridge i go tools>ps>image processor and it returns a message "Image Processor.jsx could not be found." I updated cc to no avail. i am on mac 10.7.5

    I go to file scripts but there is no option there for Image Processor

  • How do  I do a backup using a disk image file and SuperDuper?

    The external drive won't mount on the desktop even though the power light shows up on the external drive case. I want to back up the files on the computer, Powerbook G4 Panther in a hurry as the computer keeps shutting down on me.
    I opened up SuperDuper which I normally use for backups and there was a message that said it couldn't find the drive or something like that. Then there was a window to choose where I was copying from, and it came up with the hard drive name. Then another window came up with a disk image icon which is the place to copy to. I named it "Copyofharddrive", but I am not sure if this is right. I then pressed "Click" and then it told me it was going to erase the volume "Copyofharddrive" and asked if that was OK.
    I am scared of doing the wrong thing and erasing my hard drive. I only have 12GB left on my hard drive too. I am trying to copy 100GB of data onto the disk image file. Will that work out?
    I have never done this before. I don't understand disk image files. I just want to back up the data so that if the computer or the hard drive crashes I can then put the files on another computer.
    Is a disk image a suitable way to do a backup and can I restore the hard drive exactly as it was on the hard drive on another hard drive using the disk image? Do I have enough space on the Powerbook to do the backup? Am I following the correct steps in doing the backup on Superduper? Why does it ask me if it's OK to erase the volume "Copyofharddrive" when I jsut created it?
    Thanks for all your help.

    If you only have 12 GBs of space on your hard drive then how will you fit 100 GBs of data into a disc image file on that hard drive?
    If your external drive is not functioning then you cannot do any kind of backup to it. And, you cannot backup your hard drive to your hard drive.
    What you need is another external hard drive with at least 100 GBs or more of free space that you could use for a backup. However, if you have the unpaid version of SuperDuper, then SD will erase the backup drive before making a full clone of your internal drive.

  • Opening tiff image file and finding pixel values at each point

    I want to open a tiff image file using java.Than i want to find out the pixel values at each point.Also if possible red,green and blue values.
    please mail me answer or code if possible on mail id:
    [email protected]

    Use Java Advanced Imaging to open the Tiff. There is
    a tutorial on it. Look to the left for tutorials, look
    for JAI, do what it says.
    For getting the pixels, do this:
    Use a PixelGrabber to get pixels in array:
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
    pg.grabPixels();
    Use a MouseMotionListner for
    mouseMoved(MouseEvent moueEvent)
    pixel = pixels[mouseEvent.getX() + (mouseEvent.getY()*width)]
    int alpha = (pixel >> 24) & 0xff;
    int red = (pixel >> 16) & 0xff;
    int green = (pixel >> 8) & 0xff;
    int blue = (pixel ) & 0xff;
    Look up the API for MouseMotionListener, PixelGrabber, etc...

  • Photo cd contains only "alias" files and I cannot find my images....

    A few months ago, I burned a few photo cds.  I created these by dragging the files from my camera's memory card to the cd folder and then burned them.  I thought I was being careful and checked each cd after it was complete to confirm the photos were all there.  At the time all looked fine.  I then erased the camera memory card to create more usable space.  Now those same cds only contain alias files and my images cannot be located in any files or folders.  Can I recover or did I make a mistake with something that used to be so simple??  Thank you for any suggestions and help with this.

    Your cd's only had aliases burned to them. When you checked the contents of a burned CD the memory card would have been still mounted, so the aliases automatically found the original files and opened them. This will only work if the memory card with the original photos is mounted.
    The correct procedure is to create a Burn Folder. (File / New Burn folder). With the memory card connected, drag the photos to the Burn folder. You can rename the folder, say Photos. When you are ready to burn, go to File menu and and you will see the option: Burn Photos to Disk.
    After the burn, you can trash the Burn folder, or reuse it.
    In fact the Burn folder also contains just aliases, but when you burn, the original items are found and burned to the CD.
    p.s. To copy the actual files (rather than aliases) from the memory card you have to hold the Option key down when you drag and drop.

  • Finder won´t work. It doesn´t open any of my files, and when I try to force quit, it flahses, so i can´t click it. Help!!

    I have a Macbook Pro. I´ve just installed Lion version 10.7.3.
    Basically, one day I turned on my computer, and all my desktop folders and pictures were missing. And the finder just kept flashing with screen that said "finder quit while trying to restore all it´s windows" And you had the option between clicking To re-open the windows or not. Thing is, doesn´t matter what you clicked, because the thing kept flashing, so you couldn´t click it.
    I ended up using the "killall finder" Code in terminal to close it.
    But when that ended, turns out i can´t accsess any of my files. I can search them in spotlight, and if they are images, i can see them, but I´m uncapable of using my folders because they won´t open. Also, if you click the "Finder" app, it just opens the "All my files" Tab, for a split second before closing. I can´t force quit it, because when i open the force quit tab, the finder keeps flashing, so I can´t click it. Finder is killing me.

    Lightroom doesn't use the Camera Raw plug-in. All of the Camera Raw technology is part of the Lightroom program. You will either have to upgrade to Lightroom 5 or use the DNG converter to create digital negative copies that can be used with Lightroom 4.

Maybe you are looking for

  • Cannot start managed server via WLST - 'Overriding the ListenPort ...'

    Hello everyone I've created a development domain that has two machine, each of them has two weblogic server instances. On machine-2, I've started NodeManager already. I started WLST tool, connect to AdminServer and invoke 'start' command to start man

  • What is the default font defined by JSR 226-SVG Scalable Vector Graphics

    The question is briefly as follows Do we have to include <font></font> tag inside the SVG file? Or is there any default font available to use?

  • UPDATE CASCADE

    Hi, Does ORACLE 8 supports UPDATE CASCADE feature, if so, please explain it to me. Bye Sundaram Ganesh null

  • I need button help...

    I'm trying to set up something with multiple buttons on it. When these buttons are clicked lines will appear on the screen. I went through the process of making the buttons and I drew the lines in the hit frame of the button, but when I test it nothi

  • Wifi issue on iphone 6 and 5s ios 8.02

    Apple team, My wife and I having a wifi issue when we upgrade to the ios 8.02! Such a shame to gettig this feeling. We need the phone to work and using wifi is a way to finish our job quickly! Please fix this ASAP!