quartz-graphics

iPhone clip image with path

限于喜欢 提交于 2019-11-29 04:34:02
I would like to clip an image with path. In the book Programming with Quartz there is an example on how to draw a circle clipped by a rectangular path (p.37), and there is also a chapter on image masking with existing image as stencil (Ch.10). But I'm still not sure about how to clip an existing image using path. Is there any example or pointer? Here is a sample that should work, it sets the clipping area as a path(this path in my case is an elipse, you could use a rect). Then the image that will be clipped is drawn. Method drawRect: is the one that draws the UIView's context in my case. -

Releasing renderInContext result within a loop

懵懂的女人 提交于 2019-11-29 04:16:13
I have a method which is called in a loop, that looks something like this: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, PAGE_WIDTH, PAGE_HEIGHT)]; background.image = backgroundImg; for (UIView *view in viewArray) { [background addSubview:view]; } UIGraphicsBeginImageContext(background.frame.size); [background.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); for (UIView *view in background.subviews) [view

Convert html file to PDF Document in iOS using Cocoa-Touch

喜欢而已 提交于 2019-11-28 22:09:44
I want to convert local html file on iPhone to PDF document. I have used the following code I found online to generate PDF file from Picture, I tried to replace the image with the html file but it failed. I would very much appreciate your help. Thanks in advance, // Our method to create a PDF file natively on the iPhone // This method takes two parameters, a CGRect for size and // a const char, which will be the name of our pdf file void CreatePDFFile (CGRect pageRect, const char *filename) { // This code block sets up our PDF Context so that we can draw to it CGContextRef pdfContext;

CALayer and Off-Screen Rendering

人盡茶涼 提交于 2019-11-28 21:57:37
I have a Paging UIScrollView with a contentSize large enough to hold a number of small UIScrollViews for zooming, The viewForZoomingInScrollView is a viewController that holds a CALayer for drawing a PDF page onto. This allows me to navigate through a PDF much like the ibooks PDF reader. The code that draws the PDF (Tiled Layers) is located in: - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx; And simply adding a 'page' to the visible screen calls this method automatically. When I change page there is some delay before all the tiles are drawn, even though the object (page) has

Detect if CGPoint within polygon

回眸只為那壹抹淺笑 提交于 2019-11-28 20:33:46
I have a set of CGPoints which make up a polygon shape, how can I detect if a single CGPoint is inside or outside of the polygon? Say, the shape was a triangle and the CGPoint was moving hoizontally, how could I detect when it crossed the triangle line? I can use CGRectContainsPoint when the shape is a regular 4-sided shape but I can't see how I would do it with an odd shape. You can create a CG(Mutable)PathRef (or a UIBezierPath that wraps a CGPathRef ) from your points and use the CGPathContainsPoint function to check if a point is inside that path. If you use UIBezierPath , you could also

How exactly to make a CGImageRef from an image on disk

蹲街弑〆低调 提交于 2019-11-28 19:55:35
I've looked around everywhere to no avail. I'm doing some image loading in a thread and since UIKit is not thread safe I'm going to have to store the images as CGImageRefs but I can't figure out how to do this. I haven't played with any of the Quartz stuff before so it's confusing me. Basically I just need to load a JPG from the disk into a CGImageRef. Also for bonus points, is there anyway to load a GIF into a CGImageRef? Jerry Jones gcamp is more or less correct, you are pretty safe to use this on a background thread, but to answer your question, I believe the following would work.

Drawing a PNG Image Into a Graphics Context for Blending Mode Manipulation

不羁岁月 提交于 2019-11-28 19:54:38
I need to draw a series of PNGs into a CGContext so I can blend them together: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetBlendMode(context, kCGBlendModeOverlay); Currently I have my app working based on just drawing each image as a UIImageView and adding them as a subview to the view file via: [self addSubview:someImageView] ...but this doesn't allow for blending mode manipulation, right? Currently the UIImageView vars are being assigned via: someImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image-name.png"]]; So I've tried replacing those with

Getting text position while parsing pdf with Quartz 2D

試著忘記壹切 提交于 2019-11-28 19:53:50
another question regarding pdf parsing... Just read PDF Reference version 1.7 "5.3.1 Text-Positioning Operators" and I am a little bit confused. I wrote some code to get transformation matrix and initial text position. CGPDFOperatorTableSetCallback (table, "MP", &op_MP);//Define marked-content point CGPDFOperatorTableSetCallback (table, "DP", &op_DP);//Define marked-content point with property list CGPDFOperatorTableSetCallback (table, "BMC", &op_BMC);//Begin marked-content sequence CGPDFOperatorTableSetCallback (table, "BDC", &op_BDC);//Begin marked-content sequence with property list

How to generate thumbnails from a PDF document with iPhone SDK?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 19:46:04
I have read the Apple PDF documentation with Quartz . But I do not know how to generate the thumbnails from a PDF document... Any idea/sample code ? Here is my sample code. NSURL* pdfFileUrl = [NSURL fileURLWithPath:finalPath]; CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfFileUrl); CGPDFPageRef page; CGRect aRect = CGRectMake(0, 0, 70, 100); // thumbnail size UIGraphicsBeginImageContext(aRect.size); CGContextRef context = UIGraphicsGetCurrentContext(); UIImage* thumbnailImage; NSUInteger totalNum = CGPDFDocumentGetNumberOfPages(pdf); for(int i = 0; i < totalNum; i++ ) {

Is it possible to alter the letter-spacing/kerning of a font with Cocoa Touch?

你说的曾经没有我的故事 提交于 2019-11-28 19:36:23
I've been scouring the Internet for a while now for information on how one can alter the letter-spacing/kerning of a font within UIKit. My fear is, that like using your own custom fonts, you simply can't. Which would be terrible news. I know Apple is protecting us from bad design with these constraints, but they're also preventing us from implementing really great design too. What do people suggest I do? Use the font with the standard kerning, people probably wouldn't notice the difference anyway. Find someone's hacked class to get the look the user deserves after parting with their hard