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?
          Simple AIR for iOS Package for selecting a cameraroll photo or taking a photo and processing it.
          Copyright 2012 FIZIX Digital Agency
          http://www.fizixstudios.com
          For more information see the tutorial at:
          http://www.fizixstudios.com/labs/do/view/id/air-ios-camera-and-uploading-photos
          Notes:
          This is a barebones script and is as generic as possible. The upload process is very basic,
          the tutorial linked above gives information on how to post the image along with data to
          your PHP script.
          The PHP script will collect as $_FILES['Filedata'];
          import flash.display.MovieClip;
          import flash.events.MouseEvent;
          import flash.events.TouchEvent;
          import flash.ui.Multitouch;
    import flash.ui.MultitouchInputMode;
          import flash.media.Camera;
          import flash.media.CameraUI;
          import flash.media.CameraRoll;
          import flash.media.MediaPromise;
    import flash.media.MediaType;
          import flash.events.MediaEvent;
          import flash.events.Event;
          import flash.events.ErrorEvent;
          import flash.utils.IDataInput;
          import flash.events.IEventDispatcher;
          import flash.events.IOErrorEvent;
          import flash.utils.ByteArray;
          import flash.filesystem.File;
          import flash.filesystem.FileMode;
          import flash.filesystem.FileStream;
          import flash.errors.EOFError;
          import flash.net.URLRequest;
          import flash.net.URLVariables;
          import flash.net.URLRequestMethod;
                    // Define properties
                    var cameraRoll:CameraRoll = new CameraRoll();                                        // For Camera Roll
                    var cameraUI:CameraUI = new CameraUI();                                                            // For Taking a Photo
                    var dataSource:IDataInput;                                                                                          // Data Source
                    var tempDir;                                                                                                                        // Our temporary directory
                    CameraTest() ;
                    function CameraTest()
                              Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
                              // Start the home screen
                              startHomeScreen();
                    // =================================================================================
                    // startHomeScreen
                    // =================================================================================
                    function startHomeScreen()
                              trace("Main Screen Initialized");
                              // Add main screen event listeners
                              if(Multitouch.supportsGestureEvents)
                                        mainScreen.startCamera.addEventListener(TouchEvent.TOUCH_TAP, initCamera);
                                        mainScreen.startCameraRoll.addEventListener(TouchEvent.TOUCH_TAP, initCameraRoll);
                              else
                                        mainScreen.startCamera.addEventListener(MouseEvent.CLICK, initCamera);
                                        mainScreen.startCameraRoll.addEventListener(MouseEvent.CLICK, initCameraRoll);
                    // =================================================================================
                    // initCamera
                    // =================================================================================
                    function initCamera(evt:Event):void
                              trace("Starting Camera");
                              if( CameraUI.isSupported )
                                        cameraUI.addEventListener(MediaEvent.COMPLETE, imageSelected);
                                        cameraUI.addEventListener(Event.CANCEL, browseCancelled);
                                        cameraUI.addEventListener(ErrorEvent.ERROR, mediaError);
                                        cameraUI.launch(MediaType.IMAGE);
                              else
                                        mainScreen.feedbackText.text = "This device does not support Camera functions.";
                    // =================================================================================
                    // initCameraRoll
                    // =================================================================================
                    function initCameraRoll(evt:Event):void
                              trace("Opening Camera Roll");
                              if(CameraRoll.supportsBrowseForImage)
                                        mainScreen.feedbackText.text = "Opening Camera Roll.";
                                        // Add event listeners for camera roll events
                                        cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected);
                                        cameraRoll.addEventListener(Event.CANCEL, browseCancelled);
                                        cameraRoll.addEventListener(ErrorEvent.ERROR, mediaError);
                                        // Open up the camera roll
                                        cameraRoll.browseForImage();
                              else
                                        mainScreen.feedbackText.text = "This device does not support CameraRoll functions.";
                    // =================================================================================
                    // imageSelected
                    // =================================================================================
                    function imageSelected(evt:MediaEvent):void
                              mainScreen.feedbackText.text = "Image Selected";
                              // Create a new imagePromise
                              var imagePromise:MediaPromise = evt.data;
                              // Open our data source
                              dataSource = imagePromise.open();
                              if(imagePromise.isAsync )
                                        mainScreen.feedbackText.text += "Asynchronous Mode Media Promise.";
                                        var eventSource:IEventDispatcher = dataSource as IEventDispatcher;
                                        eventSource.addEventListener( Event.COMPLETE, onMediaLoaded );
                              else
                                        mainScreen.feedbackText.text += "Synchronous Mode Media Promise.";
                                        readMediaData();
                    // =================================================================================
                    // browseCancelled
                    // =================================================================================
                    function browseCancelled(event:Event):void
                              mainScreen.feedbackText.text = "Browse CameraRoll Cancelled";
                    // =================================================================================
                    // mediaError
                    // =================================================================================
                    function mediaError(event:Event):void
                              mainScreen.feedbackText.text = "There was an error";
                    // =================================================================================
                    // onMediaLoaded
                    // =================================================================================
                    function onMediaLoaded( event:Event ):void
                              mainScreen.feedbackText.text += "Image Loaded.";
                              readMediaData();
                    // =================================================================================
                    // readMediaData
                    // =================================================================================
                    function readMediaData():void
                              mainScreen.feedbackText.text += "Reading Image Data.";
                              var imageBytes:ByteArray = new ByteArray();
                              dataSource.readBytes( imageBytes );
                              tempDir = File.createTempDirectory();
                              // Set the userURL
                              var serverURL:String = "http://www.hidden_in_this_example.com/upload.php";
                              // Get the date and create an image name
                              var now:Date = new Date();
                              var filename:String = "IMG" + now.fullYear + now.month + now.day + now.hours + now.minutes + now.seconds;
                              // Create the temp file
                              var temp:File = tempDir.resolvePath(filename);
                              // Create a new FileStream
                              var stream:FileStream = new FileStream();
                              stream.open(temp, FileMode.WRITE);
                              stream.writeBytes(imageBytes);
                              stream.close();
                              // Add event listeners for progress
                              temp.addEventListener(Event.COMPLETE, uploadComplete);
                              temp.addEventListener(IOErrorEvent.IO_ERROR, ioError);
                              // Try to upload the file
                              try
                                        mainScreen.feedbackText.text += "Uploading File";
                                        //temp.upload(new URLRequest(serverURL), "Filedata");
                                        // We need to use URLVariables
                                        var params:URLVariables = new URLVariables();
                                        // Set the parameters that we will be posting alongside the image
                                        params.userid = "1234567";
                                        // Create a new URLRequest
                                        var request:URLRequest = new URLRequest(serverURL);
                                        // Set the request method to POST (as opposed to GET)
                                        request.method = URLRequestMethod.POST;
                                        // Put our parameters into request.data
                                        request.data = params;
                                        // Perform the upload
                                        temp.upload(request, "Filedata");
                              catch( e:Error )
                                        trace(e);
                                        mainScreen.feedbackText.text += "Error Uploading File: " + e;
                                        removeTempDir();
                    // =================================================================================
                    // removeTempDir
                    // =================================================================================
                    function removeTempDir():void
                              tempDir.deleteDirectory(true);
                              tempDir = null;
                    // ==================================================================================
                    // uploadComplete()
                    // ==================================================================================
                    function uploadComplete(event:Event):void
                              mainScreen.feedbackText.text += "Upload Complete";
                    // ==================================================================================
                    // ioError()
                    // ==================================================================================
                    function ioError(event:Event):void
                              mainScreen.feedbackText.text += "Unable to process photo";

1. Create a BitmapData of the correct size of the full image
2. Use BitmapData.setPixels to create pixel data from your byteArray
3. Make a new Bitmap, Bitmap.bitmapData = BitmapData
4. Create a matrix with the correct scaling factors for your thumbnail
5. Create a new BitmapData the size of your thumb
6. Use BitmapData.draw to draw your image data from the Bitmap to the new BitmapData with the scaling matrix
7. Use BitmapData.getPixels to create a bytearray from your thumb BitmapData
8. save it
You'll have to look up the AS3 reference to see how all these methods work.

Similar Messages

  • How can I move photos from my computer to a Thumb drive?

    How can I move photos from my computer to a Thumb drive?

    https://discussions.apple.com/message/16881894#16881894
    2 way to get the icon...
    Finder>Preferences>General, check what you want to show on Desktop.
    Finder>Preferences>Sidebar, check what you want to show in the Sidebar of all windows.

  • How can I transfer photos from ipad 1 to pc

    I have an ipad 1 - ios 5.1.1
    I want to transfer the photos on the ipad to a windows 8 pc.
    Should be a really simple operation - yes? wrong.
    After visiting 30+ webpages, downloading various 3rd party software (and deleting them again) - I am still unable to transfer photos from my ipad to a windows pc.
    I connect the ipad 1 to a pc using cable.
    PC shows ipad.
    Then you get the option to import photos (Which 20+ websites just repeat).
    Contained in the DCIM Folder is 2 thumbnail photos. Yes - just 2. Two.
    Stored on the ipad is nearly 3,000 photo's. NOT 2!
    So how do you move photos from an ipad to PC?
    Next problem.
    Someone recommended using Syncios - wonderful.
    All photos found.
    All photos copied - except they are copied as thumbnails.
    It would seem that ipad stores your photos as a thumbnail - but when you email the photo the true size is sent. (Thumbnail is 11kb - when I attach the same photo to an email it shows it as 1.1mb)
    So - apart from creating and sending 3000 emails - so that I can transfer photos at their original resolution - HOW DO YOU TRANSFER PHOTOS FROM IPAD 1 TO A PC.
    Apple really couldn't have made a 30second operation more difficult - or deliberately impossible.
    There is NO option to do this via iTunes.
    I can transfer photos from a PC to iPad using iTunes - but not the other way around.
    So - please - does anyone have a degree in astro-physics that can explain how a person is supposed to transfer full sized photos, that are stored as thumbnails - from an iPAD 1 to a Win 8 pc?
    ps... and yes I am irritated. This has taken me 2 days so far, and still unable.
    pps... and no, I really don't need people posting - oh yes I have the same problem... I need answers.

    HHow did the photos get on your iPad? since the original iPad does not have a camera, the photos were either received in emails, copied from the web or synced from your computer. If they were copied from emails or the web they should be available to copy off the iPad using whatever Camera or image capture application you have on your computer. Connect your iPad, start the application and transfer the photos.
    if the photos were synced from your computer, they should still be on the computer used to sync from.

  • How can I export photos from my iPad or iPod to my main computer or hard drive. My old computer died and I want to get my photos onto my new computer. Thanks in advance.

    HOw can I export photos from my iPad or iPod to my main computer? My old computer died with my photos on it but I want to move my photo library from my iPad or iPod to the computer I just bought. Thanks for any help you can give.

    Sorry but your iPhoto library is not on an iPad or iPod - you may have photos there (most likely low resolution copies) but not an iPhoto library - dying computers (along with software and human errors) are why you always must have a backup - now is the time to load it
    LN

  • How do we send photos from an iphone to a business email so that the photo shows up as an attachment vs. a part of the body of the email?

    How do you email photos from an iphone to a business email so that the photo shows up as an attachment vs. a part of the body of the email?

    Eric, thanks for the info about the pictures, it worked.   The mail icon is not the one that came with the mac(it looks like a stamp with an eagle) this appears at a notepad with a ruler,paintbrush and pencil.  I can not open it, I did not download it and now I can not turn off the computer with shutdown I have to manually turn if off by pressing the power button.   This can not be normal.  Any suggestions.  thanks,  Ellen

  • How to I copy photos from my ipod classic back onto my pc?

    How to I copy photos from my ipod classic back onto my pc? My hardrive recently crashed and the photos on my ipod are the only copies I have! The photos were synced onto th ipod originally - not saved or copied as file transfer.

    See Recover your iTunes library from your iPod or iOS device. I'm not sure which of the recovery tools can do photos offhand, but unless you chose the option to include full res. originals when you loaded the device then what they extract will be fairly low res. If you did opt for full res. then they should be visible on the iPod's drive when viewed in disk mode.
    tt2

  • How do I delete photos from iPod Touch?  Some photos do not have the trash basket option!

    How do I delete photos from iPod Touch?  Some photos do not have the trash basket option!
    When I first synced my iPod Touch with my laptop, it uploaded a lot of photos onto the iPod.  I now wish to delete those but it does not seem as a straight forward option!

    For photos synced to the iPod you have to unsync them:
    To delete photos from your device
    In iTunes, select the device icon in the Devices list on the left. Click the Photos tab in the resulting window.
    Choose "Sync photos from."
    On a Mac, choose iPhoto or Aperture from the pop-up menu.
    On a Windows PC, choose Photoshop Album or Photoshop Elements from the pop-up menu.
    Choose "Selected albums" and deselect the albums or collections you want to delete.
    Click Apply.
    http://support.apple.com/kb/HT4236

  • How can I transfer photos from an IPhone 5 to an IPad 2 using a cable.  I have tried using the lightning to firewire adapter with my current lead but this only seems to allow a download from the Ipad to the Iphone and not the other way around.

    How can I transfer photos from an IPhone 5 to an IPad 2 using a cable.  I have tried using the lightning to firewire adapter with my current lead but this only seems to allow a download from the IPad to the IPhone and not the other way around.

    The devices are not designed for transfer of that kind.  Use Photo Stream as suggested by another poster, or transfer photos to your computer (a good idea anyway since they will be lost if your device needs to be reset), then use iTunes to sync them to the other devices.

  • How do I copy photos from my Mac to my iPad without deleting the ones that are there?

    I understand how to sync photos from my iPhoto library to my iPad. I want to copy photos from my Mac to the iPad without syncing, because syncing deletes everything on the iPad that isn't included in my sync selections. In addition,I have several iPhoto libraries and want to copy photos from each of them to the iPad. A further issue is that apparently photos can be synced from only one computer to the iPad -- how would I copy photos from a different computer? (What happens when I buy a new Mac?) I am extremely experienced with Mac, iPhoto/Aperture, iPad, etc. A year or two ago I transferred 1000 photos to the iPad but I don't remember how, and it was probably done with my previous Mac. Now I just want to add some recent photos without deleting the ones that are there. Bottom line: is there a way to add photos to an iPad without syncing and losing what's there?

    You can still sync the photos and keep the photos that are already on the device. You have to include all of the albums or events in the pictures folder that you sync from. If you are using iPhoto, select that in the Sync Photos from drop down menu and then select all of the albums or events that you want to sync. Make sure to check Selected Albums, events, faces and automatically include (no events). Using that option will allow you to choose exactly which albums and events to sync.
    You have to remember that all photos must be included in every sync so you cannot sync photos from iPhoto today and then try to sync photos from another folder tomorrow, or you will erase all of the photos that were synced from iPhoto. You need to maintain one main Photos syncing folder for the photos that you want to transfer to the iPad. You can have subfolders within that one main folder and you can selectively sync those subfolders. You just have to place all of the photos that you want to sync into one main iPad syncing photos folder.
    There are WiFi transfer apps that allow you to transfer photos to the iPad without having to sync with iTunes. I use this one. This app (and others like it) will allow you to use multiple computers to transfer photos.
    Wireless Transfer App Easily send photos to iPhone/iPad ...

  • How can i put photos from my mac to my ipad touch

    How can i put photos from my mac to my ipad touch
    I have them in an album.
    Thanks for your help

    See:
    iOS and iPod: Syncing photos using iTunes

  • How can I put photos from my iPod to my computer wihout using camera roll?

    How can I sync photos from iPod touch to my computer without using camera roll?

    How did the photos get on the iPod? If they were synced from another computer you need a third-party program like PhoneView or TouchCopy.

  • How can I transfer photos from my iphone to my computer without emailing each one to myself

    how can I transfer photos from my iphone to my computer without emailing each one to myself, and I thought they would be in icloud but I can't find them

    Pics taken with the iphone are imported to your computer as with any other digital camera ( as explained in the manual).
    Pics synced to your iphone from your computer should still be on the computer.
    iOS: Importing personal photos and videos from iOS devices to your computer

  • How can I delete photos from camera roll to give me more storage

    I Upgraded to an iPhone 4 from a 3GS (mainly because it was a 99¢ promotion).  I have only a little over 1GB—maybe less—left and it doesn't have music on it yet.  I figured my photos are the answer but can't figure out how to delete them from the camera roll.  Any body out there know how?.  Also other ways of getting more room on my 4?  I know a 4s comes with more unless someone gives one away, or another 99¢ promotion comes along I can't afford it on a fixed income.
    THanks!

    Paulajain
    You might find htis link helpful
    http://www.gottabemobile.com/2012/05/28/how-to-delete-old-photos-from-iphone-cam era-roll/
    Once you delete these photos, if you haven't saved them on a computer they will truly gone.
    Cheers

  • How can you transfer photos from one phone to another

    How can you transfer photos from phone to phone

    If you are trying to get all the photos from an old phone to your new phone, you could sync the old phone which would create a backup containing your Camera Roll. Then connect the new phone and follow the prompts to register and name your new phone. You will then be given the choice of restoring data to your new phone from a backup of the old phone. This will replace any existing data on the new phone with the data from the backup so it's really the best option if the other phone is new.
    Another option would be to connect the phone to your computer and import your photos to iPhoto or the My Pictures folder. Then you could sync the other phone and under the Photos tab in iTunes you could choose the folders/albums of pictures you want on the phone. They will not be in the Camera Roll, but they will be on the phone.
    I hope this helps.

  • How do I transfer photos from one library to another?

    how do I transfer photos from one library to another?

    Best way is using the paid version of iPhoto Library Manager - http://www.fatcatsoftware.com/iplm/ - 
    you can export form one library and import into the other one but this does not get all metadata or versions
    LN

Maybe you are looking for