cgcontext

Flatten UIViews Subviews to UIImage iPhone 3.0

戏子无情 提交于 2019-12-03 01:41:06
I have a UIView that has several UIImageViews as subviews. Each of these subviews has had different affine transform applied. I would like to take what amounts to a screen capture of my UIView, capturing it as a UIImage, or some other image representation. The method I have tried already, rendering the layers to a CGContext with: [view.layer renderInContext:UIGraphicsGetCurrentContext()]; doesn't preserve the positioning or other affine transformations of my subviews. I would really appreciate a kick in the right direction. Try this: UIGraphicsBeginImageContext(self.view.frame.size); [self

iOS: Improving speed of image drawing

人盡茶涼 提交于 2019-12-03 00:42:38
I have a sequence of images that I want to animate ( UIImageView supports some basic animation but it's not sufficient for my needs). My first approach was to use UIImageView and set the image property when the image. This was too slow. The reason for the poor speed was due to the drawing of the images (which surprised me; I assumed the bottle neck would be loading the image). My second approach was to use a generic UIView and set view.layer.contents = image.CGImage . This gave no noticeable improvement. Both of these approaches must be performed on the main thread. I think the poor speed is

CALayer vs CGContext, which is a better design approach?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 23:29:52
I have been doing some experimenting with iOS drawing. To do a practical exercise I wrote a BarChart component. The following is the class diagram (well, I wasnt allowed to upload images) so let me write it in words. I have a NGBarChartView which inherits from UIView has 2 protocols NGBarChartViewDataSource and NGBarChartViewDelegate. And the code is at https://github.com/mraghuram/NELGPieChart/blob/master/NELGPieChart/NGBarChartView.m To draw the barChart, I have created each barChart as a different CAShapeLayer. The reason I did this is two fold, first I could just create a UIBezierPath and

Drawing Hollow circle in iPhone

匆匆过客 提交于 2019-12-02 23:29:11
i need to draw the following image The Gray part is what i want to draw over another image what is the Code i need to use using CGContext methods, i tried using the CGContextAddArc but failed because when i fill the stroke the center hollow is also filled with the grey texture. Any help appreciated. Info : I have the Complete Blue Image , i need to add the Semi Circle above the blue image Thanks Have a look at Filling a Path in the Core Graphics documentation. Basically, what you do is add two arcs to your path (the outer and the inner one) and then use Core Graphics fill rules to your

Erasing after drawing with CGContext

两盒软妹~` 提交于 2019-12-02 21:11:52
I'm trying to do a simple drawing app for the iPad where you can draw on a picture, and I'm using CGContext stuff to do it but the way I originally planned on handling erasing was to just draw over stuff with white...except I just realized today that it doesn't work when you're drawing onto another image because then when you "erase" you'll also "erase" the background image as well. Is there any way to support actual erasing? Thanks! Display the user's drawing in a layer above the image. Then erasing is as simple as drawing a transparent patch on the drawing layer in order to let the image

Drawing triangle/arrow on a line with CGContext

▼魔方 西西 提交于 2019-12-02 19:38:41
I am using the framework of route-me for working with locations. In this code the path between two markers(points) will be drawn as a line. My Question: "What code should I add if I want to add an arrow in the middle(or top) of the line, so that it points the direction" Thanks - (void)drawInContext:(CGContextRef)theContext { renderedScale = [contents metersPerPixel]; float scale = 1.0f / [contents metersPerPixel]; float scaledLineWidth = lineWidth; if(!scaleLineWidth) { scaledLineWidth *= renderedScale; } //NSLog(@"line width = %f, content scale = %f", scaledLineWidth, renderedScale);

CGContext: how do I erase pixels (e.g. kCGBlendModeClear) outside of a bitmap context?

社会主义新天地 提交于 2019-12-02 19:36:26
I'm trying to build an eraser tool using Core Graphics, and I'm finding it incredibly difficult to make a performant eraser - it all comes down to: CGContextSetBlendMode(context, kCGBlendModeClear) If you google around for how to "erase" with Core Graphics, almost every answer comes back with that snippet. The problem is it only (apparently) works in a bitmap context. If you're trying to implement interactive erasing, I don't see how kCGBlendModeClear helps you - as far as I can tell, you're more or less locked into erasing on and off-screen UIImage / CGImage and drawing that image in the

How can I render line faster than CGContextStrokePath?

戏子无情 提交于 2019-12-02 18:35:36
I'm plotting ~768 points for a graph using CGContextStrokePath. The problem is that every second I get a new data point, and thus redraw the graph. This is currently taking 50% CPU in what's already a busy App. Graph drawing is done in drawRect in a UIView. The graph is time based, so new data points always arrive on the right hand side. I'm thinking a few alternative approaches: Draw with GLKit (at cost of not supporting older devices) and seems like a lot of work. Do some kind of screen grab (renderInContext?), shift left by 1 px, blit, and only draw a line for the last two data points. Have

Erasing on UIImageView

依然范特西╮ 提交于 2019-12-02 17:19:27
How can I erase content on front UIImage by swiping finger on it and display UIImage that is back side of UIView. I had used following code in - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event to erase front image: -(void)eraseDrawingContents { UIGraphicsBeginImageContext(frontImage.frame.size); [frontImage.image drawInRect:CGRectMake(0, 0, frontImage.frame.size.width, frontImage.frame.size.height)]; CGContextSaveGState(UIGraphicsGetCurrentContext()); CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES); CGContextSetLineCap(UIGraphicsGetCurrentContext(),

How to procedurally draw rectangle / lines in swift using CGContext

孤者浪人 提交于 2019-12-02 17:15:26
I've been trawling the internet for days trying to find the simplest code examples on how to draw a rectangle or lines procedurally in Swift. I have seen how to do it by overriding the DrawRect command. I believe you can create a CGContext and then drawing into an image, but I'd love to see some simple code examples. Or is this a terrible approach? Thanks. class MenuController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = UIColor.blackColor() var logoFrame = CGRectMake(0