cgcontext

Animate colour of circle drawn using CGContextFillEllipseInRect

强颜欢笑 提交于 2019-12-13 04:47:55
问题 I have a UIView that draws a circle inside it using the following code: -(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, myColor); CGContextFillEllipseInRest(context, myRect); } I want to animate this circle to a grey color... How can I achieve this? -(void)fadeToGrey { // What goes here? } 回答1: You should use CAShapeLayer as a layer class and do your drawing inside setLayerProperties: method. drawRect: will not be

Create CGContext for CGLayer

99封情书 提交于 2019-12-13 03:36:32
问题 I want to pre-render some graphics into CGLayer for fast drawing in future. I found that CGLayerCreateWithContext requires a CGContext parameter. It can be easily found in drawRect: method. But I need to create a CGLayer outside of drawRect: . Where should I get CGContext ? Should I simply create temporary CGBitmapContext and use it? UPDATE: I need to create CGLayer outside of drawRect: because I want to initialize CGLayer before it is rendered. It is possible to init once on first drawRect

CAGradient layer not visible on view

我是研究僧i 提交于 2019-12-12 21:01:02
问题 I try to add a CAGradient effect in a pie chart I make with Core Graphics. It turns out I am not able and certainly not understand very well how to apply it to a view that is part of a CGPath... override func draw(_ rect: CGRect) { ... func arc(myRadius: CGFloat, myStartAngle: CGFloat, myEndAngle: CGFloat) { // This is the pie chart segment context?.setFillColor(phenotypeColor.cgColor) context?.move(to: center) context?.addArc(center: center, radius: finalRadius, startAngle: myStartAngle,

CoreGraphics: Image Transparent Background

北战南征 提交于 2019-12-12 14:19:35
问题 I am trying to draw an image with a 2px transparent border: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.0); CGContextAddRect(context, CGRectMake(0.0, 0.0, outputImageSize.width, outputImageSize.height)); CGContextDrawPath(context, kCGPathFill); [image drawInRect:CGRectMake(2.0, ((outputImageSize.height - userPhotoImageSize.height) / 2.0) +2.0, userPhotoImageSize.width -4.0, userPhotoImageSize.height -4.0)]; UIImage *screenshot =

What this error is invalid context 0x0?

怎甘沉沦 提交于 2019-12-12 08:55:04
问题 I wrote the following code in ViewDidLoad // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -(void)viewDidLoad { [super viewDidLoad]; NSString *str = [NSString stringWithFormat:@"Veer"]; CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB(); CGFloat values[4] = {55.0, 0.0, 0.0, 1.0}; CGColorRef glowColor = CGColorCreate(rgbColorspace, values); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetShadowWithColor( context,

The following graphical code tagged as Leak by iOS ARC

时光毁灭记忆、已成空白 提交于 2019-12-12 03:47:22
问题 (UIImage *) cropToSquare:(UIImage *)_image { if(_image.size.height < _image.size.width) { CGRect drawRect = CGRectMake(0, 0, _image.size.height, _image.size.height); UIGraphicsBeginImageContext(drawRect.size); CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGRect cropArea = CGRectMake (((_image.size.width - _image.size.height)/2), 0, _image.size.height, _image.size.height); CGContextTranslateCTM(currentContext, 0.0, _image.size.height); CGContextScaleCTM(currentContext, 1.0, -1

UIGraphicsGetImageFromCurrentImageContext crop to content and not to bounding box

半腔热情 提交于 2019-12-12 00:02:26
问题 I have an area where a user can add their signature to an app, to verify an order. They sign with their touch. The only thing is, the frame for the signature is large, and if the user were to make a signature very small, when I save the image, I'm left with a wealth of empty space around the image, which, when I add it to an email further down the process can look horrible. Is there any way, using that I can crop the image to whatever the bounds of the actual content is, and not the bounds of

UIGraphicsGetCurrentContext and UIScrollView

两盒软妹~` 提交于 2019-12-11 18:09:43
问题 I'm trying to save all of the contents of a UIScrollView to a .pdf. I found some tutorials for saving the current view, and they all rely on creating a CGContextRef using UIGraphicsGetCurrentContext() . Right now, I capture my view with just CGContextRef context = UIGraphicsGetCurrentContext(); [myView.layer renderInContext:context]; And that works fine for a plain UIView. However, when I try to pass a UIScrollView as myView , it passes the visible part of the UIScrollView fine, but anything

UIGraphicsBeginImageContext created image stays in memory forever

假如想象 提交于 2019-12-11 14:52:31
问题 I'm creating many colour variations of an image using Core Graphics. I need to create about 320 in total but gradually, the memory usage of the app keeps increasing until it crashes. From Instruments, I see that more CGImage objects are being created and stay alive. I want to release them because I store the images to the cache directory in PNG format. I have searched through all other solutions I could find without success. Any help is appreciated. Thanks. Here's the main part: +(UIImage *

invalid context 0x0 within custom UIView

允我心安 提交于 2019-12-11 14:23:33
问题 I have the following code for a custom view. @IBDesignable class SplitCircleView: UIView { override init(frame: CGRect) { super.init(frame: frame) draw(frame) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) draw(frame) } override func draw(_ rect: CGRect) { self.backgroundColor = .clear drawSlice(rect: self.frame, startPercent: 87.5, endPercent: 37.5, color: .green) drawSlice(rect: self.frame, startPercent: 37.5, endPercent: 87.5, color: .red) } func drawSlice(rect: