quartz-2d

‘invalid context 0x0’ error when using CGContext* functions

非 Y 不嫁゛ 提交于 2019-11-28 01:19:17
/* Adding the Path */ UserGraphBuff = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(UserGraphBuff,5,10,0,1); CGContextSetLineWidth(UserGraphBuff, 2 ); CGContextBeginPath(UserGraphBuff); //line to last user point CGContextAddLineToPoint(UserGraphBuff, (*xVal)[sizeof xVal / sizeof *xVal - 1], (*yNewVal)[sizeof yNewVal / sizeof *yNewVal - 1]); //line to rest of user points in reverse order for (int i = sizeof xVal / sizeof *xVal - 1; i > -1; i--){ CGContextAddLineToPoint(UserGraphBuff, (*xVal)[i], (*yNewVal)[i]); } //EOFill CGContextEOFillPath(UserGraphBuff); Above is the code I am

Rotate CGImage taken from video frame

╄→尐↘猪︶ㄣ 提交于 2019-11-27 20:34:57
问题 This is Apple's code (from Technical Q&A QA1702) for getting a UIImage from a video buffer. Unfortunately, the image returned is rotated 90 degrees. How do I edit this so that the image returned is correctly oriented? - (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer { CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(imageBuffer, 0); void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer); size_t bytesPerRow =

Most efficient way to draw part of an image in iOS

心不动则不痛 提交于 2019-11-27 16:53:08
Given an UIImage and a CGRect , what is the most efficient way (in memory and time) to draw the part of the image corresponding to the CGRect (without scaling)? For reference, this is how I currently do it: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGRect frameRect = CGRectMake(frameOrigin.x + rect.origin.x, frameOrigin.y + rect.origin.y, rect.size.width, rect.size.height); CGImageRef imageRef = CGImageCreateWithImageInRect(image_.CGImage, frameRect); CGContextTranslateCTM(context, 0, rect.size.height); CGContextScaleCTM(context, 1.0, -1.0);

iPhone: Blur UIImage

梦想与她 提交于 2019-11-27 14:17:17
问题 In my iPhone application I have a black-and-white UIImage . I need to blur that image (Gaussian blur would do). iPhone clearly knows how to blur images, as it does that when it draws shadows. However I did not found anything related in the API. Do I have to do blurring by hand, without hardware acceleration? 回答1: Try this (found here): @interface UIImage (ImageBlur) - (UIImage *)imageWithGaussianBlur; @end @implementation UIImage (ImageBlur) - (UIImage *)imageWithGaussianBlur { float weight[5

Create a table of contents from a pdf file

女生的网名这么多〃 提交于 2019-11-27 11:59:21
I'm using quartz to display pdf content, and I need to create a table of contents to navigate through the pdf. From reading Apple's documentation I think I am supposed to use CGPDFDocumentGetCatalog, but I can't find any examples on how to use this anywhere. Any ideas? Update: Still haven't found a solution for this. I tired Alex' solution but the output I get looks like this: 2011-07-27 09:16:19.359 LDS Scriptures App-iPad[624:707] key: Pages 2011-07-27 09:16:19.361 LDS Scriptures App-iPad[624:707] key: Count 2011-07-27 09:16:19.362 LDS Scriptures App-iPad[624:707] pdf integer value: 238 2011

How to set up a user Quartz2D coordinate system with scaling that avoids fuzzy drawing?

送分小仙女□ 提交于 2019-11-27 11:01:47
问题 This topic has been scratched once or twice, but I am still puzzled. And Google was not friendly either. Since Quartz allows for arbitrary coordinate systems using affine transforms, I want to be able to draw things such as floorplans using real-life coordinate, e.g. feet. So basically, for the sake of an example, I want to scale the view so that when I draw a 10x10 rectangle (think a 10-inch box for example), I get a 60x60 pixels rectangle. It works, except the rectangle I get is quite fuzzy

How can I draw an arrow using Core Graphics?

ぐ巨炮叔叔 提交于 2019-11-27 10:12:45
I need to draw line with arrow on its end in my Draw app. I'm not good in trigonometry, so can't solve this problem. The user put his finger on the screen and draw the line in any direction. So, the arrow should appear on the line end. UPDATE I've posted a Swift version of this answer separately. ORIGINAL This is a fun little problem. First of all, there are lots of ways to draw arrows, with curved or straight sides. Let's pick a very simple way and label the measurements we'll need: We want to write a function that takes the start point, the end point, the tail width, the head width, and the

What's the difference between Quartz Core, Core Graphics and Quartz 2D?

China☆狼群 提交于 2019-11-27 09:10:21
问题 I wonder if someone can distinguish precisely between these? For my understanding, Core Graphics is just a "Framework Package" which contains Quartz Core and Quartz 2D. But I'm not sure about if Quartz 2D actually is Quartz Core? Maybe someone can draw some lines there? What makes up the differences between these? When looking at the documentation, I see Quartz Core is listing up all the Core Animation stuff only. So Quartz Core == Core Animation? 回答1: From the Quartz 2D Programming Guide:

Draw glow around inside edge of multiple CGPaths

故事扮演 提交于 2019-11-27 05:14:45
问题 If I create a CGMutablePathRef by adding together two circular paths as shown by the left image, is it possible to obtain a final CGPathRef which represents only the outer border as shown by the right image? Thanks for any help! 回答1: What you are asking for is the union of bezier paths. Apple doesn't ship any APIs for computing the union of paths. It is in fact a rather complicated algorithm. Here are a couple of links: http://www.cocoadev.com/index.pl?NSBezierPathcombinatorics http:/

How to use CGAffineTransformMakeRotation?

我怕爱的太早我们不能终老 提交于 2019-11-27 04:03:47
I want to draw text use Quartz 2D. The "menu" direction is wrong. I want "Menu" still readable and have 45 degree with X-axis. Below is my code: CGContextSelectFont(context, "Arial", 12, kCGEncodingMacRoman); CGContextSetTextDrawingMode(context, kCGTextFill); CGContextSetRGBFillColor(context, 0, 0, 0, 1); // 6 CGContextSetRGBStrokeColor(context, 0, 0, 0, 1); CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0)); CGContextSetTextMatrix(context, CGAffineTransformMakeRotation(45)); CGContextShowTextAtPoint(context,10, 10, "Menu", 4); CGAffineTransformMakeRotation