Reputation: 1355
I'm fairly new in Android development so please forgive me if it's a stupid question. Basically I have an iPhone app,which will compress UIImage into NSData, using UIImageJPEGRepresentation method, this is not a problem. The question begins when I am trying to read this data on an Android device. I'm transferring the image data (NSData)from iPhone to Android, and I want to display the image on Android. How should I do so? Is there any customised class that can do function similar to UIImage imageWithData in Java, that can decode the data and turn it into Bitmap? Or should I try to encode and decode using a different but stand method? If so, what are the options? Thank you so much for your help!
Upvotes: 0
Views: 968
Reputation: 1355
After further digging and researching, I found some interesting and useful classes if anyone is interested. https://code.google.com/p/crossmobile/source/browse/src/xmioslayer/src/org/xmlvm/iphone/?r=68eaa3b2fa6ee05e8034bd517b45b490c50c7bb7 This is google cross mobile code, with them, you can use NSData and other class method that was originally meant for iOS developing. However that's not how I solve the problem above. There're two ways to pass an image from iPhone(UIImage) to Android(Bitmap), or the other way around. First, upload the image into your own server, (by using AFNetwork in iOS, not sure about android), then get the url of the image, then pass this url to the other device as a string. Or, convert UIImage to NSData, then from NSData to NSString (using Base64Encoding), then use NSJsonSerializatioin to parse whatever NSString, NSArray or NSDictionary to Json Object. Send the Json object, and try to decode it on the other device. Although the first method is recommended, I actually went with the second one since I wish to deal the data locally with or without internet. If anyone needs sample code, just ask, I'll post. And that's pretty much it! Happy coding!
Upvotes: 3