core-graphics

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

我怕爱的太早我们不能终老 提交于 2019-12-03 07:01:18
问题 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

How to adjust drop shadow dynamically during an UIImageView rotation?

China☆狼群 提交于 2019-12-03 06:59:37
I use the following to code to add drop shadow: letterE.layer.shadowColor = [[UIColor blackColor] CGColor]; letterE.layer.shadowOffset = CGSizeMake(2.5, 2.5); letterE.layer.shadowRadius = 3.0; letterE.layer.shadowOpacity = 0.95; and the following to rotate: CABasicAnimation* rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0]; rotationAnimation.duration = 5.0; rotationAnimation.cumulative = YES; rotationAnimation.repeatCount = 1.0; rotationAnimation.timingFunction =

CoreGraphics drawing causes memory warnings/crash on iOS 7

房东的猫 提交于 2019-12-03 06:20:50
After updating my iPad (mini) to iOS7 I experienced that my drawing app is lagging and crashing after a few strokes. Now, when I run the app with Instruments/memory allocation tool in xcode 5, I see that the VM: CG raster data category is filling up rapidly when drawing on the screen. There seems to be a multitude of CGDataProviderCreateWithCopyOfData calls being made, each 3.00Mb in size. After continous drawing the app receives memory warnings, and usually terminates. The code basically strokes paths into an imagecontext, more or less like this: UIGraphicsBeginImageContext(self.view.frame

Drawing Text with Core Graphics

旧城冷巷雨未停 提交于 2019-12-03 06:20:39
问题 I need to draw centered text to a CGContext. I started with a Cocoa approach. I created a NSCell with the text and tried to draw it thus: NSGraphicsContext* newCtx = [NSGraphicsContext graphicsContextWithGraphicsPort:bitmapContext flipped:true]; [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:newCtx]; [pCell setFont:font]; [pCell drawWithFrame:rect inView:nil]; [NSGraphicsContext restoreGraphicsState]; But the CGBitmapContext doesn't seem to have the text rendered

How do I add an outer glow to a UIImage or UIImageView or UIView

≡放荡痞女 提交于 2019-12-03 06:18:26
问题 I want to add a FADED shadow/outer glow to a UIImage / UIImageView / UIView but I know no Core Graphics at all. Edit: Please Help!! 回答1: Take the approach outlined by Cirrostratus, keep a cached copy of it, and then apply a transform to change the size and/or position of the image while dragging. (warning, this is not functional/tested code, but should get you started) -(UIImage*)addGlowToImage:(UIImage*)imageInput; { CGRect newSize = imageInput.bounds; CGImageRef theImage = imageInput

How Can I Record the Screen with Acceptable Performance While Keeping the UI Responsive?

折月煮酒 提交于 2019-12-03 06:18:16
问题 I'm looking for help with a performance issue in an Objective-C based iOS app. I have an iOS application that captures the screen's contents using CALayer's renderInContext method. It attempts to capture enough screen frames to create a video using AVFoundation. The screen recording is then combined with other elements for research purposes on usability. While the screen is being captured, the app may also be displaying the contents of a UIWebView, going out over the network to fetch data,

Pie chart using Charts library with swift

可紊 提交于 2019-12-03 05:56:57
问题 I am integrating pie chart in my app using Charts library and getting issue with chart data my code is import UIKit import Charts class ViewController: UIViewController { @IBOutlet weak var pieChartView: PieChartView! override func viewDidLoad() { super.viewDidLoad() let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] let unitsSold = [10.0, 4.0, 6.0, 3.0, 12.0, 16.0] setChart(dataPoints: months, values: unitsSold) } func setChart(dataPoints: [String], values: [Double]) { var dataEntries:

Subtract CGRect from CGRect — largest piece of one not containing the other

假如想象 提交于 2019-12-03 05:20:32
How I can substract one CGRect from another? I want the result R1 - R2 to be the largest subrectangle of R1 that does not intersect R2. Example 1 : +----------------------------------+ | +--------+ | | | R2 | | | | | | | +--------+ R1 | | | | | | | +----------------------------------+ R3 = CGRectSubstract(R2,R1); +----------------------+ | | | | | | | R3 | | | | | | | +----------------------+ Example 2 : +-----------------------+----------+ | | | | | R2 | | | | | R1 +----------+ | | | | | | +----------------------------------+ R3 = CGRectSubstract(R2,R1); +-----------------------+ | | | | | |

Drawing triangle/arrow on a line with CGContext

一笑奈何 提交于 2019-12-03 05:15:51
问题 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 *=

CoreGraphics FillPath And Stroke Path

喜夏-厌秋 提交于 2019-12-03 04:46:24
I need to draw an hexagon and fill it with a color build with an Image as pattern. I did: CGContextSaveGState(context); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetFillColorWithColor(context, [[UIColor colorWithPatternImage:[UIImage imageNamed:@"patternerba.png"]] CGColor]); CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]); CGContextSetLineWidth(context, 3.0); // drawing hexagon here... CGContextStrokePath(context); CGContextFillPath(context); [[NSString stringWithFormat:@"Foo"] drawAtPoint:innerRect.origin withFont:[UIFont fontWithName:@"Helvetica" size