views:

590

answers:

4

Is it possible to render a vector image file on the iPhone in the same way that one can render a bitmap (png, jpeg) file? I have tried eps and pdf files, neither of which seems to work – they are displayed correctly in Interface Builder but do not display when run.

The console outputs a message along the lines of 'Could not load the "image.pdf" image referenced from a nib in the bundle with identifier "com.yourcompany.project"'

All my searches on this come up with discussion of drawing a vector files using OpenGL, etc. Is this the only way? Since there is no mention of vector file support I am unsure if my files are not being loaded because of problems with the files (I have tried different versions), or because they are not supported.

+1  A: 

PDFs can be loaded by UIWebView. If you need more control you can use Quartz 2D to render PDFs: Quartz2D

Hua-Ying
+1  A: 

There is no direct support for vector graphics formats like there is for PNG and JPEG. Any vector graphics rendering would be done programmatically, i.e. stroking and filling path objects using Quartz drawing calls.

willc2
A: 

Yes, it supports SVG.

You can convert your vector files to SVG and render them by conversion to javascript using a library like Raphael. My Raphael-based web sites have flash-like functionality and they render perfectly on the iPhone--the benefit of web standards!

Plynx
+2  A: 

One can render PDF images natively, and create them as well, with Core Graphics. Something like this:

void DrawPDF (CGContextRef context, NSString *name)
{
    NSURL *url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: name ofType: @"pdf"]];

    CGPDFDocumentRef doc = CGPDFDocumentCreateWithURL((CFURLRef)url);
    CGPDFPageRef page = CGPDFDocumentGetPage(doc, 1);

    CGRect box = CGPDFPageGetBoxRect(page, kCGPDFCropBox); //kCGPDFArtBox);
    CGContextDrawPDFPage(context, page);

    CGPDFDocumentRelease(doc);
}

UIWebView of course for SVG.

humasect

related questions