core-graphics

Can a CGImage be added to the contents property of a CAShapeLayer?

别来无恙 提交于 2020-01-06 18:08:36
问题 I have a custom view with a layerClass override like: + (Class) layerClass { return [CAShapeLayer class]; } I want to be able to add a CGImage to the contents property like so: - (void) animateView { UIImage *layerImage = ...; CAShapeLayer *layer = (CAShapeLayer *)self.layer; layer.contents = layerImage.CGImage; //....Do other fun animations here } Are there other properties I need to set, or other ways to get the shape layer to render the contents of the image for animation? 回答1: I would

get the UIImage (or CGImage) from drawRect

回眸只為那壹抹淺笑 提交于 2020-01-06 18:07:33
问题 I'm calling the following code from drawRect - (void) drawPartial:(UIImage *)img colour:(UIColor *)colour { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CGContextTranslateCTM(context, 0.0, self.bounds.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextDrawImage(context, self.frame, img.CGImage); if (colour!=nil) { CGContextSetBlendMode (context, kCGBlendModeColor ); CGContextClipToMask(context, self.bounds, img.CGImage); CGContextSetFillColor

get the UIImage (or CGImage) from drawRect

混江龙づ霸主 提交于 2020-01-06 18:07:07
问题 I'm calling the following code from drawRect - (void) drawPartial:(UIImage *)img colour:(UIColor *)colour { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CGContextTranslateCTM(context, 0.0, self.bounds.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextDrawImage(context, self.frame, img.CGImage); if (colour!=nil) { CGContextSetBlendMode (context, kCGBlendModeColor ); CGContextClipToMask(context, self.bounds, img.CGImage); CGContextSetFillColor

Issue with ellipse angle calculation and point calculation

試著忘記壹切 提交于 2020-01-05 13:35:12
问题 I have a UIView with bounds (w, h) and I am trying to calculate angles and point on a ellipse which is centred at view's mid point i.e. centre is (w * 0.5, h * 0.5). I continuously change the size of view and ellipse so following values are from console for a instance of values. For this instance, (w, h) = (150.000000, 300.799988) and radii are (rx, ry) = (52.500000, 105.279999) Now, I try to find angle of point P1(x,y) (30.784275, 93.637390) on this ellipse using following code: CGFloat

Issue with ellipse angle calculation and point calculation

混江龙づ霸主 提交于 2020-01-05 13:35:10
问题 I have a UIView with bounds (w, h) and I am trying to calculate angles and point on a ellipse which is centred at view's mid point i.e. centre is (w * 0.5, h * 0.5). I continuously change the size of view and ellipse so following values are from console for a instance of values. For this instance, (w, h) = (150.000000, 300.799988) and radii are (rx, ry) = (52.500000, 105.279999) Now, I try to find angle of point P1(x,y) (30.784275, 93.637390) on this ellipse using following code: CGFloat

CGContextDrawRadialGradient For Non-Circular Glow

做~自己de王妃 提交于 2020-01-05 10:19:56
问题 I'm able to use CGContextDrawRadialGradient to make a sphere that does an alpha fade to UIColor.clearColor and it works. However, I'm trying to do this type of thing: While placing some strategic spheres around makes for an interesting effect (similar to LED backlights in strategic places), I would love to get a true glow. How can I draw a glow around a rounded rectangle in drawRect ? 回答1: You can create a glow effect around any path using CGContextSetShadowWithColor , but you don't get

CGContextDrawRadialGradient For Non-Circular Glow

佐手、 提交于 2020-01-05 10:19:52
问题 I'm able to use CGContextDrawRadialGradient to make a sphere that does an alpha fade to UIColor.clearColor and it works. However, I'm trying to do this type of thing: While placing some strategic spheres around makes for an interesting effect (similar to LED backlights in strategic places), I would love to get a true glow. How can I draw a glow around a rounded rectangle in drawRect ? 回答1: You can create a glow effect around any path using CGContextSetShadowWithColor , but you don't get

How to draw an NSString with an specific height on to an perfectly matching bitmap?

时光总嘲笑我的痴心妄想 提交于 2020-01-05 10:04:04
问题 I have an NSString like @"Hello World" and want to convert that into an bitmap with exactly 20 pixels height. The width of the bitmap should match the width of the text. I know there are some NSString UIKit additions that can draw text, but I don't know how to draw the text with an bounding box of exactly 20 pixels height (text fits perfectly into this height) into an bitmap that has the perfect size to carry the text? Is there an easy way to do this? This must also work with Chinese,

How to draw an NSString with an specific height on to an perfectly matching bitmap?

半世苍凉 提交于 2020-01-05 10:04:01
问题 I have an NSString like @"Hello World" and want to convert that into an bitmap with exactly 20 pixels height. The width of the bitmap should match the width of the text. I know there are some NSString UIKit additions that can draw text, but I don't know how to draw the text with an bounding box of exactly 20 pixels height (text fits perfectly into this height) into an bitmap that has the perfect size to carry the text? Is there an easy way to do this? This must also work with Chinese,

CALayer rendering issues with diagonal dashed line

别来无恙 提交于 2020-01-05 08:31:33
问题 I've created a dashed CAShapeLayer using the code below. The line draws correctly when its path is on a perfectly horizontal plane. However as soon as the path moves up or down, the line suffers from some issues. See the images as an example. CGMutablePathRef linePath = CGPathCreateMutable(); CGPathMoveToPoint(linePath, NULL, startShapeLayer.centerX, startShapeLayer.centerY); CGPathAddLineToPoint(linePath, NULL, endShapeCenter.x, endShapeCenter.y); CGPathCloseSubpath(linePath); CAShapeLayer