Open a disk image and trimming for a picture control

Hi people,

I try to let my users (in a browser) to select/open a disk file (image type) so that they can see and then save it to the server.  I can use the FileReference object very well and load its 'result' directly in a MX:Image control.  However, before I do that I want to crop the selected image square.  I also want to resize the image down, but that will come later, once I get the job of cropping.

I'm essentially taking the FileReference result bytearray and conversion to a BitmapData object.  Then I 'extract' a place of this BitmapData object data in a new BitmapData object.  Then I need to get * that * BitmapData object in the mx:image control.  I tried to use a Bitmap of the to do, but the mx:image that results, while the 'companies' displays correctly, as a white Virgin region.  Throughout, the variables seem to be "complete" data and seem to have developed properly.  I looked at a few sites that show images cropping and copies, but they always start with images 'preload '.  I modeled my code after them, if necessary.

Here is my code:

This is called when the user clicks a button to "search for a file on disk.

private function setPhoto (): void
{
create the instance of FileReference
_fileRef = new FileReference();

_fileRef.addEventListener (Event.SELECT, onFileSelected);

Look 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 leave the event managers treat the result...

}

private void onFileSelected(evt:Event):void
{
_fileRef.load (); the result of the "load" will be managed by the Manager of 'complete '.
}

private void 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 fine, however, it would not be cropped
}

private void 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 into the bitmap data, we can crop and then resize it later
so, we need a "place" of the image cropped from the original
so... First, we get a square of the image of "size".
If the image is larger than the scale, we will take a place as large as the image and as high as it is wide, from 5% down from the top
If the image is larger that high, we will take a square as large as the image and as wide as it is high, 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 = Uchr;
var needCrop:Boolean = true; default is to crop
var croppedBD:BitmapData;

If (Uchr > curW)
{
cropY = Math.round (Uchr *. 05); departure at 5% down
cropH = cropW;
}
ElseIf (curW > Uchr)
{
cropX = Math.round (curW/2) - Math.round (Uchr/2); start in the Middle, 'back' by half the height
cropW = cropH;
}
on the other
{
needCrop = false; It's already a square!  nothing to do (except for resizing)
}

If (needCrop)
{
croppedBD = new BitmapData (cropW, cropH); at this point, it is 'empty', then the full
var fillPoint:Point = new Point (0,0); given that we will fill in the upper, left pixel and rollover
var fillRect:Rectangle = new Rectangle (cropY, cropW, cropX, cropH);
croppedBD.copyPixels (loadBD, fillRect, fillPoint);
}
on the other
{
croppedBD = loadBD;
}

imgPhoto.source = new Bitmap (croppedBD);  The result is an appropriate size, but the image in white-white
}

And here is the mxml for the image:

< mx:Image id = "imgPhoto" x = "40" y = "126" maxWidth = "200" maxHeight = "200" / >

Thank you!

-David

Hello

You've been around the solution.

In "onLoaderComplete(event:Event):void", at the beginning, you create a BitmapData called 'loadBD', you forgot just to fill it with the content of the loaderInfo.

private void 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

Tags: Flex

Similar Questions

  • "Lightroom_5_LS11_mac_5_7.dmg" for Mac update my Lightroom 5.6 (build 974614) but when I try to open it I get the error message "Lightroom_5_LS11_mac_5_7.dmg cannot open the disk image is not recognized. I am running OS 10 of Yosemite

    I downloaded "Lightroom_5_LS11_mac_5_7.dmg" for Mac that allows to update my Lightroom 5.6 (build 974614), but when I try to open it I get the error message "Lightroom_5_LS11_mac_5_7.dmg cannot open the disk image is not recognized. I am running Yosemite OS 10.10 on a Macbook Pro (retina, 13 inches, end 2012 with 2.9 GHz Intel Core i7 processor).

    Vk2mh looks that the download was not complete or corrupt.  When you download the update from?  Have you tried to download it again?

  • How to make a disk image of work for my windows 98se boot (original is long dead)

    How to make a disk image of work for my windows 98se boot (original is long dead).  I have a copy of Windows 98SE bought new off the years of the plateau.  I now have a 64-bit system, so I can't run it natively, but I discovered that I can't even run at all, because I don't have a working bootable floppy!  I thought that the CD is bootable, when I used it a long time ago, but now it does not start if I have used the disk? Anyway, can I get a driver Microsoft w/CD install/bootable disk, or do I have another decent resource?

    Thank you. You can contact me to the * address email is removed from the privacy *.

    http://www.bootdisk.com/bootdisk.htm

  • You can use a single hard drive to store an image disk backup and restore for multiple computers?

    I have a couple of computers that I recently installed Win7 on. As soon as I do an install I always do a backup image is preparing for the worst. Do I need a separate hard drive for each computer that I do a backup or image can I put all my images on a hard drive backup? I already have two separate a HDs different images, but would like to have them all in one place. I already tried a straight copy of an image to HAND HD I would use like, but without success. Is this possible or do I really a backup image HD?

    Depends on what you use for backup.  in General, you need not to have a picture in HD.

    Personally, I like acronis true image home 2012 (free trial) because it is flexible, easy to use and workjs each time.

  • What are disk images and can they be removed

    In downloads, I have a lot of disk images containing memory - such as Chrome - beyond 1 GB.

    I can remove them? Does make a difference? What are doing?

    All the other tips to speed up my mac because it is really slow!

    Have just updated the OS to Sierra - & that made matters worse, not better!

    A disk image is a convenient way for a developer to package and deliver the program. Once you have copied the program in your Applications folder, there is no reason to keep. You can safely remove. Note: Make sure that you have copied the image program in your applications folder before deleting.

  • Damaged disk image and can not install Photoshop Elements in MacbookPro

    When you try to install Photoshop Elements 9 in my new MacBook, I get the following message when I click on the install icon: 'Install' is corrupted and cannot be opened. You must eject the disk image.

    I tried to download Photoshop Elements 9 on the following pages:

    Download Photoshop Elements versions 9, 8, 7

    and

    Download Photoshop Elements | 10, 12, 14, 11, 13

    But no luck so far, don't get the same error message.

    This should be closer to 2.0 GB or 2,154,935,181 bytes.

    try using another browser to download and extract the message 2 to see if this applies to you.

  • How to open a .jpg image and modify it.

    I can't seem to find a way to open a .jpg image or any image in Flash Professional CC. I'm quite new to this, so sorry if this sounds like a stupid question. When I go to file > open, I see only .as, .fla, .jsfl, .xsfl, and .xml files. I don't have an option to be able to display .jpg or .png images. I would appericate if someone could take the time and answer this question for me

    Thank you

    If you want to change a jpeg or png image, do it with a separate program like Fireworks or Photoshop.  After you import the image into Flash, you can edit the picture again in these separate applications and update the image that you have imported into Flash via the properties option in the menu of the image library and clicking the button to update.

  • in el capitan 'Image Capture' will not open a "Disk Image" file of Adobe

    I'm trying to update to the latest version of Adobe Flash Player.  My iMac (El Capitan, latest version) told me that 'image Capture' cannot open a file in 'picture disc '.  I'm stuck.

    Where did you download this disk Image from? Only direct downloads on the Adobe site can trust: https://get.adobe.com/flashplayer/

  • Central folder for images and sounds for use or NOT?

    Hello.

    I produce a lot of graphics and sounds for an online e-learning course.

    Can I just confirm something please?

    Should I put most of my graphics which will be shared with other sovereign funds in its own dedicated swf.

    As it is cached, I guess this would be the best idea.

    BUT

    Isn't it also take longer for a game or a loading screen if it must import the special mc inside the large resources.swf.

    In addition, exactly how to get that mc.

    For example I want mc mountain (which resides inside the resources.swf) in my flyingGame.swf.

    Must FlyingGame import resources.swf and then ' search in ' mountain mc everytime.

    Is it good or bad.

    I have getconfused on how best to go about this. So ebody mentioned RSL - which is better or I am actually already libraries are cached and shared anyway?

    Libraries that nest within other will do exactly as you said, do load unnecessary things. It also creates a dependency that might be very useless. If a game is updated using a shared resource, all other games updates for nothing.

    For example for (other than sprite sheets) fast web design, it has always been strongly suggested to limit the number of HTTP requests. If you need to load 50 images, audio files, 30, etc., this will not work terribly effective assets as well as external.

    If you manage to get the assets on the sprite sheets, I think that these more flexible overall, especially with an atlas. Keep in external files spirit are easy to change, do not have the SWF indigestion and are also cached.

    The only thing THAT SWF gives you is perhaps an advantage of speed and the speed of development if you load dozens and dozens of foreign assets. If you went outside and found you had to load 50-100 + assets then pack in a single SWF file is much more advantageous.

    Audio is an ideal target for group into SWF, if you can because each file must be a separate download. That said, it's did nothing to make the audio is smaller that you could do with similar settings in any other audio encoder to the right settings SWF. MP3's MP3, etc...

    Your answer could lie between several game strategies. Fund rulers for some games, if possible assets elsewhere and a combination of the two institutions. It really depends on your game.

  • Cannot create disks C and D for the programs and data on HP Pavilion dv6-6c53cl with 1 TB HD

    Just bought new HP Pavilion dv6-6c53cl Entertainment Notebook - 1 TB HD (it's good).

    Bad news is that there are FOUR partitions (C, SYSTEM, RECOVERY, TOOLS HP) with the C-drive with 904 GB.   If I understand correctly, you cannot shrink C and create a 5th partition for data.  It seems that you cannot have more than four partitions...

    (quote from sevenforums.com: ' you already have 4 primary partitions - you can't have more. ") If you try to make another c: partition using disk management, you will turn your (entire) disk into a dynamic disk. You don't want to do that! »

    HP experts: Is it true? I can't shrink C and create a disk for data D?  Can I combine one or more of your three auxiliary drives (SYSTEM, RECOVERY, TOOLS HP) and a disk for data D?

    I've always heard that it was not a good idea to combine all, Windows programs, system etc all in the same giant partition with lots of photos, songs, financial data, Word files, etc etc.

    Please notify.

    I have a 1 TB hard drive and use the main C for all files. I use images software to make my own custom recovery solution, having 1 large partition makes it simpler. Custom recovery options

    However, your question is how to have another partition. Daniel made a Guide on everything this HERE

  • Disk size, disk speed and workflow for video editing?

    I want to edit the video in 1080 p/24 drawn up to four Canon DSLR and the multi camera editing. This will be usually social and professional events, so I expect to have total raw images less than 300 GB in size by the event. My current computer (PC of Q6600) can't seem to handle that very well, so I'm going to buy a new computer. In fact, I bought all the parts except for storage because I have not determined what would be the best configuration. I need your help with this please! What is a good an event video production workflow? And what would my setup disk for this computer?

    Here's what I come up with so far.

    First of all, I put the OS and programs on a small SSD. I have a 128 GB crucial MX100 of the old system. Fact!

    Now for the hardest part - the workflow. I think that after I have the video of an event, I want to save them on the computer and save it. I would like to save the raw images, even after I put the final product. So I think I need a lot of extra space. So, I think 2 x 3 TB RAID 1 for this.

    I think that having this as a media drive would slow me during the editing process, so a fast SSD could be good here. Say an 256 GB Crucial or Samsung SSD. I copy media from RAID 1 disk on that drive, so it would be a working copy. Once the project is completed, I delete all media and copy the files from the next project media here.

    When I finished editing the video, I would export it to another drive. I don't think it should be too big, but the sequential write speed should be fast. On my old system, I have a 3 TB external drive (Buffalo Drivestation, USB3.0) that I can use. I also have a blue WD 1 TB I put in RAID 0 if I buy a second. Would this work better?

    Does make sense? Did I miss something?

    Storage element most important to your system is to buy a Samsung SM951 512 GB SSD m2 or wait a few weeks until the Samsung 950 PRO m2 512 GB SSD is available and install either on your motherboard socket m2.  I would then like he use to all of your files to current project.  When you have finished this project archive on your hard drive or external drive.  If you need multiple direct projects, you can add another standard 6 Gbps SATA III SSD to intermediate stage, or as I do on my X-99 system get a Samsung T1 512 GB USB3 Flash drive. It will be about 2 x faster than your WD Blue or your Buffalo drive.  With your Crucial MX100 is 128 GB, you'll just have to frequently clean the Adobe "média Cache" and "Media Cache files" files which, by default, go to the C: drive to prevent their excessive become large.  This is just temporary files that will get re-created if you navigate to an older project.  In this case frequent probably means that when you change projects.

    Here's Crystal disk mark first tests my SM951 in my X 99, i7-5960 X, 64 GB, computer and other hand the Samsung Q1, USB 3.0, 512 GB, Flash Drive

    . First with our first Pro BenchMark (PPBM) with intensive chronology of disk test, I can write to the SM951 to 1500 MB/s.

    I actually use the T1 of Samsung USB 3.0 on my laptop for all my editing, then take most of the time my X 99 to export and making the disc.  As you can see large sequential files, this is two times faster than hard drives and doesn't have any fall speed because it fills up like hard drive.

  • make the partition of SL disk image and restore to another hard drive

    Hi, I have partitioned my hard drive, a mountain lion other snow leopard partition. My goal is to put now the partition with snow leo on it's own hard drive and delete a partition on the original hard drive. Could someone point me in the right direction to start this?

    Thank you

    Randall

    The Finder, choose utilities go to menu, open disk utility, use the restore function to move the volume of Snow Leopard and check that it works.

    When you're done, select all of the disk and click the Partition tab. If the partition of Mountain Lion is the first in the list, delete the one snow leopard, drag the slider under the Mountain Lion partition as far down as it will go and click on apply. If it's the second, restore the system of Cougar in the first volume, restart it and proceed as above.

    (141364)

  • Images: Click to open the larger image and in place

    Hello

    I've often seen websites that have a picture thunbnails, Gallery when you click Open a larger version in place in the same Web page. There is often a 'activity' spinning before opening more.

    Anyone know where I can get the code for this or the same feature for my site please?

    Thank you

    Darren

    Have a look here fancyBox - fancy Lightbox Alternative jQuery

  • Why I get a blue with double arrows box when I open my file image and music, he also appears with my documents.

    It is very annoying and I can't get rid of

    Hello

    They are called icons and they are used by some programs, such as backup programs online, storing files online programs (such as Skydrive, etc.) and other programs.

    They reflect the State of these files.

    Status, such as should be saved has been saved, hasn't been downloaded yet, etc, etc.

    What happens when you right click the icon of recovery?

    Let us know.

    Concerning

  • Importing images to Lightroom for Apple pictures on El Capitan system. Is there a compatibility issue

    I can't import pictures enom Apple Photos in Lightroom. Is there a compatibility issue with the operating system of El Capitan?

    Hi DickD,

    From now there no Plugin in Lightroom to import images from Apple Photos in Lightroom.

    However please take a look in the following thread: photos stored in the News Photos Apple can quickly transferred to Lightroom? I am not at all satisfied with this new Apple 'fix'.

    Kind regards

    Tanuj

Maybe you are looking for

  • I started firefox in safe mode. Now all my Add-ons disappeared, my favorites, my preferences... everything! What is hell?

    Here's what was contained in the dialog box. I checked all the boxes and choose the option "make changes and restart". Nothing has emerged to indicate that I was doing permanent changes... no type 'Are you sure you want to do' things... nothing. Fire

  • Noisy dvd/cdrw drive Sat Pro A100

    Hello Ive just got my new laptop A100 Sat Pro and check that everything worksI noticed that when accessing a dvd in the dvd/cdrw Mat * one player combo UJDA770He is much stronger with pronounced sounds/cries as he accessed but subsequently, hecan pla

  • Tecra M3 - how to make it quieter?

    It seems that the fan turns itself on even when I don't do anything with the laptop and there are only a few essential background running processes. I tried setting cooling performance to 'Performance' instead of ' max performance ", but it still mak

  • WIN8 in compaq cq58-d50el

    laptop has been infected with the virus and need to do a factory restore.  How can I access the recovery Partition which became invisible? I did not restore win8 dvd Thank you

  • decommissioning of windows 8 for windows xp

    My sister jst had hp 650 with windows 8 on it and wants windows xp loaded on it.will appreciate solutions to the ds.tanx in advance