1

I have an app that is built in AS3/Air for iOS devices. In the app I allow users to select images from the camera roll using the code from here http://www.adobe.com/devnet/air/articles/uploading-images-media-promise.html however with some images, when they are uploaded they are rotated incorrectly.

I have read there are some EXIF data but I have no idea how to get this or if this is the right data to get to set orientation.

Any help is appreciated.

puks1978
  • 3,667
  • 11
  • 44
  • 103

2 Answers2

1

Yes, you do need to read the EXIF. There has been a nice discussion about it @Adobe forum, let me see if I can still find it... Here it is: http://forums.adobe.com/thread/875157 Read the steps in that thread you have to make to make this work on iOS!

Let me point out an important issue as the "final" implementations in that thread are not exactly bulletproof (I am not sure whether there is some new info there, I won't go through it now, too long):

Note the constructor of ExifInfo returns if the stream is not validated:

public function ExifInfo(stream:ByteArray) {
    if (!validate(stream)) {
        return;
    }
    _tiffHeader = new TIFFHeader(stream);
    readIFDs(stream);
    readThumbnail(stream);
}

Therefore you need to check whether there exists an ifds object in the exif instance. If you don't do this check, you will be thrown a null pointer exception. You could use something like this:

public static function getImageOrientation(imageData:ByteArray):String {
    var exif:ExifInfo = new ExifInfo(imageData);
    var ifd:IFD;
    var str:String = "";


    if(exif.ifds) { //happens only if there is info
        ifd = exif.ifds.primary;
        for (var entry:String in ifd) {
            if(entry.toLowerCase() == "orientation"){
                str = ifd[entry];
                break;
            }
        }
    }

    switch(str) {   
        case "1": //normal
            str = ImageOrientation.NORMAL;
            break;

        case "3": //rotated 180 degrees (upside down)
            str = ImageOrientation.UPSIDE_DOWN;
            break;

        case "6": //rotated 90 degrees CW
            str = ImageOrientation.ROTATED_LEFT;
            break;

        case "8": //rotated 90 degrees CCW
            str = ImageOrientation.ROTATED_RIGHT;
            break;

        case "9": //unknown & fall-thru
        default:
            str = ImageOrientation.UNKNOWN; 
            break;

    }
    return str;
}

EDIT: If you had some problems implementing it, leave a comment and I will post the complete code. But it is understandable from the thread I mentioned.

Fygo
  • 4,555
  • 6
  • 33
  • 47
  • Thanks for this. I will give it a go and let you know how I get on. I guess one question would be how to ensure orientation is correct when the image is saved on the server. Am I correct to assume I should pass the exif data to the upload script and allow PHP to rotate to correct orientation before saving to the server or should I just allow PHP to handle all EXIF stuff? – puks1978 Aug 28 '13 at 00:51
  • You have 3 options: 1. you don't do anything in Flash, you process it all on the server from the exif contained in the image file. 2. you extract the exif in Flash and pass a value with the upload, then you rotate it on the server. 3. you rotate the image in Flash (draw it into a new Bitmap, apply rotation and translate Matrix). If the original data is not needed, I would do the third. – Fygo Aug 28 '13 at 06:13
  • Thanks. I have gone with your suggestion 2, extract exif in the app and pass the orientation value to my PHP script to do the rotation. – puks1978 Aug 31 '13 at 02:35
0

puks1978. I found an article that solved your problem perfectly, which works on both iOS and Android.

http://blogs.adobe.com/cantrell/archives/2011/10/parsing-exif-data-from-images-on-mobile-devices.html

And in the same time, I would like to ask you a question about uploading files from Air on iOS device. You said you uploaded the image file to server. How did you upload the file? Which version of iOS and which version of Air SDK are you using? Did you do some configuration in the xxx-app.xml file?

I tried the same solution with you in

www.adobe.com/devnet/air/articles/uploading-images-media-promise.html 
, but the File.upload(URLRequest) did not work on iOS8. File.upload did not even send any request to the server side. It seems that the Air SDK for iOS just failed to send the http request for some reason.

You can go to the following link to see my problem about this.

ActionScript's File.upload does not work on Air SDK for iOS devices

My sample code is uploaded to github.

github.com/bluewindjava8/actionscript_file_upload_for_ios

Will you please check it for me if you have time. And will you please send me your code if it is ok? Thank you very much.

Community
  • 1
  • 1
bluewind
  • 11
  • 4