tags:

views:

301

answers:

2

How can I load vector image directly with iPhone SDK? Just as UIImage loads bitmap images.

A: 


You could try loading the image file into an NSData object and initialising the UIImage from there. Might look something like this:

NSString *path = [[NSBundle mainBundle] pathForResource:@"AnImage" ofType:@".ext"];
NSData *imgData = [NSData dataWithContentsOfFile:path];
UIImage *img = [UIImage imageWithData:imgData];
imnk
From Apple's document, UIImage only supports bitmap image. Can I put vector images (such as SVG) in imgData?
MQ Gu
UIImage only supports TIFF, JPEG, GIF, PNG, BMP, ICO, CUR, and XBM files: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImage_Class/index.html . Nothing more.
Brad Larson
OK I hadn't realised that. thx Brad. Guess that voids my answer really but I'll leave it here in case it may be of use to others.
imnk
+1  A: 

As of iPhone OS 2.1, the iPhone's WebKit supports SVG graphics natively. You should be able to use a UIWebView to load the SVG element for display. This question provides some sample code for doing so.

Brad Larson
Thanks, I'll try UIWebView.
MQ Gu