quartz-2d

How to obtain a CGImageRef from the content of an UIView?

倾然丶 夕夏残阳落幕 提交于 2019-12-10 03:00:38
问题 I have an UIView where I was drawing some stuff inside -drawRect:. Now I need a CGImageRef from this graphics context or bitmap of the UIView. Is there an easy way to get that? 回答1: Like this (typed from memory, so it might not be 100% correct): // Get a UIImage from the view's contents UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, view.contentScaleFactor); CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; UIImage *image =

iPhone App - Display pixel data present in buffer on screen

余生长醉 提交于 2019-12-10 00:34:41
问题 I have the source code for a video decoder application written in C, which I'm now porting on iphone. My problem is as follows: I have RGBA pixel data for a frame in a buffer that I need to display on the screen. My buffer is of type unsigned char. (I cannot change it to any other data type as the source code is too huge and not written by me.) Most of the links I found on the net say about how to "draw and display pixels" on the screen or how to "display pixels present in an array", but none

How to draw a triangle with QUARTZ 2D?

做~自己de王妃 提交于 2019-12-09 23:41:07
问题 I'm developing an iPhone app with 3.1.3 SDK. I'm trying to draw a triangle with transparent fill an 1px black stroke with this code: CGContextMoveToPoint(ctx, position.X, position.Y - (size.height / 2)); CGContextAddLineToPoint(ctx, position.X - (size.width / 2), position.Y + (size.height / 2)); CGContextAddLineToPoint(ctx, position.X + (size.width / 2), position.Y + (size.height / 2)); CGContextFillPath(ctx); CGContextSetLineWidth(ctx, 1.0); CGContextStrokePath(ctx);

In iOS Development, using Core Graphics and/or Quartz 2D, how can I draw a circle filled with a gradient in such a manner that it looks like a sphere?

三世轮回 提交于 2019-12-09 06:15:15
问题 So far I have looked at using CGContextDrawLinearGradient() and CGContextDrawRadialGradient(), however, with the former I can't figure out how to make the gradient look like a sphere, and with the latter, I can't figure out how to make the gradient into the shape of a sphere, because every time I try, it turns out in the shape of the full cylinder instead of only a sphere. The code I am using to current draw a 2D circle is shown below. I would like to use a gradient or any other method

Quartz 2D Graphics Contexts

不羁岁月 提交于 2019-12-08 11:54:17
问题 Why do Quartz 2D Graphics Contexts functions have to be called from within the drawRect method? Because if I call a CGGraphics context function from anywhere except from within drawRect I get messages like this: <Error>: CGContextFillRects: invalid context <Error>: CGContextSetFillColorWithColor: invalid context Actually in a subclass of UIView I do setup a Graphics Context in a method called Render. Bet when Render is called I get the above errors: - (void)Render { CGContextRef g =

Draw over screen with Quartz

大憨熊 提交于 2019-12-08 03:29:48
问题 I'm trying to work out what the best way to draw over the top of all other items on the screen on OS X. I don't want to impede the user's ability to interact with their applications, but want to 'annotate' them. I want to be able to draw up to 20 different annotations. The top half of this screenshot from Gizmodo happens to nicely show the kind of thing I want to do. http://gizmodo.com/assets/resources/2006/07/04%20Safari.jpg (sorry, I'm too new to post it as an image) The questions I think I

Reading CGImageRef in a background thread crashes the app

空扰寡人 提交于 2019-12-08 00:19:51
问题 i have a big jpeg image that i want to load in tiles asynchronously in my opengl engine. Everything works well if its done on the main thread but its slow. When i try to put the tile loading on an NSOperationBlock, it always crashes when trying to access the shared image data pointer that i previously loaded on the main thread. There must be something i don't get with background operation because i assume i can access memory sections that i created on the main thread. What i try to do is the

Annotation (notes, comments) using Quartz 2d in ios

会有一股神秘感。 提交于 2019-12-07 19:12:11
问题 I am doing PDF based application for iPad. It supports thumbnail view, Free hand comment, And annotations (Notes). Ya and I searched lot on net but I didnt find any relevant answer for making annotation on PDF using Quartz 2d. We can get PDF page info using CGPDFDictionaryRef CGPDFPageGetDictionary ( CGPDFPageRef page ); And using Annots key. bool CGPDFDictionaryGetArray ( CGPDFDictionaryRef dict, "Annots", CGPDFArrayRef *value ); you can get annotation for particular page. If I am right what

CGLayer and Anti-aliased CGPaths

末鹿安然 提交于 2019-12-07 09:40:11
问题 I am drawing several CGPaths in a Cocoa view in the drawRect method on an iPad. I started out drawing them straight to the UIGraphicsGetCurrentContext() context, but performance went south when my paths got really long. Based on several other questions, I started looking into using CGLayer s. So what I do now is to render a path inside of the CGContextRef I get from calling CGLayerGetContext . Here's the basic outline of what I'm doing: // rect comes from the drawRect: method layer =

Animating the drawing of a line

99封情书 提交于 2019-12-07 00:10:38
问题 I'm trying to animate the drawing of a line by the following way: .h CAShapeLayer *rootLayer; CAShapeLayer *lineLayer; CGMutablePathRef path; .m path = CGPathCreateMutable(); CGPathMoveToPoint(path, nil, self.frame.size.width/2-100, 260); CGPathAddLineToPoint(path, nil, self.frame.size.width/2+100.0, 260); CGPathCloseSubpath(path); self.rootLayer = [CALayer layer]; rootLayer.frame = self.bounds; [self.layer addSublayer:rootLayer]; self.lineLayer = [CAShapeLayer layer]; [lineLayer setPath:path