core-graphics

Float comparison (equality) in CoreGraphics

一笑奈何 提交于 2019-12-19 03:01:05
问题 Apple CoreGraphics.framework , CGGeometry.h : CG_INLINE bool __CGSizeEqualToSize(CGSize size1, CGSize size2) { return size1.width == size2.width && size1.height == size2.height; } #define CGSizeEqualToSize __CGSizeEqualToSize Why do they (Apple) compare floats with == ? I can't believe this is a mistake. So can you explain me? (I've expected something like fabs(size1.width - size2.width) < 0.001 ). 回答1: Floating point comparisons are native width on all OSX and iOS architectures. For float ,

How to create UIImage with vertical gradient using “from-color” and “to-color”

女生的网名这么多〃 提交于 2019-12-18 18:53:38
问题 How to create new image just with gradient colors, using "from-color" and "to-color"? 回答1: A simpler answer, using a CAGradientLayer. CGSize size = CGSizeMake(width, height); CAGradientLayer *layer = [CAGradientLayer layer]; layer.frame = CGRectMake(0, 0, size.width, size.height); layer.colors = @[(__bridge id)[UIColor blackColor].CGColor, // start color (__bridge id)[UIColor whiteColor].CGColor]; // end color UIGraphicsBeginImageContext(size); @try { [layer renderInContext

How to erase piece of UIImageView with png-brush and UIBezierPath

不问归期 提交于 2019-12-18 13:39:07
问题 I have two UIImageView, first above second. I want to erase piece of the first image with brush (brush is a png picture with soft edge) to make piece of the second image visible. I did that by this way: 1) touchesMoved and [self setNeedsDisplayInRect:[self brushRectForPoint:touch_location]]; 2) at (void)drawRect:(CGRect)rect I call [_brush drawAtPoint:touch_location blendMode:kCGBlendModeDestinationOut alpha:1]; It works ok, but frequency of touchesMoved not enough, if user moves finger too

iPhone: Drawing a curved line until it becomes a circle animation

徘徊边缘 提交于 2019-12-18 13:29:24
问题 I wish to draw a curved line until it makes a full rotation and joins to become a complete circle, just the circle outline, not filled. This has to be animated over a number of seconds. Can anyone point me in the right direction? I already asked a similar question to this but I worded it incorrectly so everyone had a hard time understanding what I meant and thus it got lost in the sea of questions. Many Thanks for any help [edit] I'm currently sub-classing UIView and overriding drawRect. I

iPhone - Jagged Edges when applying perspective to CALayer

大憨熊 提交于 2019-12-18 13:27:35
问题 I have a CALayer that I apply a perspective to using a CGTransform3D and specifying the m14 property. When the perspective is applied, the layer has jagged edges. I've heard people mention that adding a 1px transparent border around the layer will help with this. I don't know how to do that. I have tried using the border and borderWidth properties of a CALayer but the jagged edges are still there. I also tried to reduce the rect that is drawn by 1px on all sides, but it doesn't help either.

How to fill a bezier path with gradient color

假装没事ソ 提交于 2019-12-18 13:23:12
问题 I have a UIBezierPath inside my custom UIView draw(_ rect: CGRect) function. I would like to fill the path with a gradient color. Please can anybody guide me how can I do that. I need to fill the clip with a gradient color and then stroke the path with black color. There are some posts in SO which does not solve the problem. For example Swift: Gradient along a bezier path (using CALayers) this post guides how to draw on a layer in UIView but not in a UIBezierPath . NB: I am working on Swift-3

Scale CGPath to Fit UIVIew

妖精的绣舞 提交于 2019-12-18 12:19:29
问题 I need to know how I can scale down or up CGPath so it can fit UIView? Set the background color to yellow, To see the view clearly self.frame = CGRectMake(0, 0, 181, 154); self.backgroundColor = [UIColor yellowColor]; Draw CAShapeLayer CAShapeLayer *shape = [CAShapeLayer layer]; shape.path = aPath; shape.strokeColor = [[UIColor blueColor] CGColor]; shape.lineWidth = 5; shape.fillColor = [[UIColor clearColor] CGColor]; [self.layer addSublayer:shape]; Then I get This: What I want is this: Thank

Fill a UIView with diagonally drawn lines?

一世执手 提交于 2019-12-18 11:55:33
问题 How to fill a UIView like this (with some diagonally drawn white lines). PS: My intentions is about the fill not the border. Any help? 回答1: One way of achieving this would be to override the draw(_:) method of UIView and do your custom drawing there. Drawing diagonal lines is fairly simple, you just need to: Stride from 0 to width + height (along the horizontal edge of the rect, then up the vertical), by the gap + line width, converted from being a diagonal (at 45º) length to being parallel

Create a mask from difference between two images (iPhone)

拈花ヽ惹草 提交于 2019-12-18 11:44:09
问题 How can I detect the difference between 2 images, creating a mask of the area that's different in order to process the area that's common to both images (gaussian blur for example)? EDIT: I'm currently using this code to get the RGBA value of pixels: + (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy count:(int)count { NSMutableArray *result = [NSMutableArray arrayWithCapacity:count]; // First get the image into your data buffer CGImageRef imageRef = [image CGImage];

How to use a UIImage as a mask over a color in Objective-C

99封情书 提交于 2019-12-18 11:07:08
问题 I have a UIImage that is all black with an alpha channel so some parts are grayish and some parts are completely see-through. I want to use that images as a mask over some other color (let's say white to make it easy), so the final product is now a white image with parts of it transparent. I've been looking around on the Apple documentation site here: http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/dq_images.html#//apple_ref/doc