Data URL / PNG from UIImage

I have a program for iPhone with UIImage. This UIImage needs to be transferred to the javascript image object in the UIWebView. I thought this could be done using the data url that I send to the UIWebView as follows:

[wview stringByEvaluatingJavaScriptFromString:@"loadimage('%d')",dataurlfromuiimage];

So, I need to transfer my UIImage to the Data: URL. I could do it myself if I could get the PNG data, but I cannot find how to do it. If there is a better way to post this to a WebView, that's good too.

+5
source share
2 answers

To get the NSData view of your PNG image, use

NSData *dataForPNGFile = UIImagePNGRepresentation(yourImage);

Similarly, a JPEG view can be obtained using

NSData *dataForJPEGFile = UIImageJPEGRepresentation(yourImage, 0.9f);

, NSData, Documents, writeToFile: atomically:, , URL ( ). Base64 NSData, . - JavaScript Base64.

+22

, UIImage , , UIImage. - NSData (, JPEG ou PNG). BASE64. , Apple, : http://www.cocoadev.com/index.pl?BaseSixtyFour

0

All Articles