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.
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.
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.
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.
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.
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.
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.
PDFs can be loaded by UIWebView. If you need more control you can use Quartz 2D to render PDFs: Quartz2D
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!
You can use something like http://www.codeautomat.com/ to convert SVG files to Core Graphics Objective-C code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With