Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the iPhone render vector graphics files directly? What formats are supported?

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.

like image 353
Stephen Avatar asked Mar 01 '10 20:03

Stephen


People also ask

What is a vector file type?

Vector files are images that are built by mathematical formulas that establish points on a grid. Raster files are composed of the colored blocks commonly referred to as pixels.

Are jpegs vector files?

Vector graphics are commonly found today in the SVG, WMF, EPS, PDF, CDR or AI types of graphic file formats, and are intrinsically different from the more common raster graphics file formats such as JPEG, PNG, APNG, GIF, WebP, BMP and MPEG4.

How do vector graphics work?

Vector graphics are computer images created using a sequence of commands or mathematical statements that place lines and shapes in a two-dimensional or three-dimensional space. In vector graphics, a graphic artist's work, or file, is created and saved as a sequence of vector statements.

What are vector graphics used for?

Graphic designers use vector graphics to create graphics that need to be scaled. The nature of vector graphics, where each line, curve, shape, and colour is mathematically defined, lends itself to creating images that can be scaled down for a business card or up for a billboard.


5 Answers

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.

like image 53
humasect Avatar answered Oct 04 '22 22:10

humasect


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.

like image 20
willc2 Avatar answered Oct 04 '22 22:10

willc2


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

like image 26
Hua-Ying Avatar answered Oct 04 '22 22:10

Hua-Ying


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!

like image 38
Plynx Avatar answered Oct 04 '22 22:10

Plynx


You can use something like http://www.codeautomat.com/ to convert SVG files to Core Graphics Objective-C code.

like image 33
jeanox Avatar answered Oct 04 '22 23:10

jeanox