puks1978
puks1978

Reputation: 3697

AS3 air app on ios image orientation wrong after saving to server

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.

Upvotes: 1

Views: 1524

Answers (2)

bluewind
bluewind

Reputation: 11

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.

Upvotes: 0

Fygo
Fygo

Reputation: 4665

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.

Upvotes: 1

Related Questions