cgcontextdrawimage

How to clear circle in CGContext in iOS

倾然丶 夕夏残阳落幕 提交于 2020-05-26 09:09:51
问题 I want create image using CGcontext. This is simple image with white or black background. also I want to add transperent part which is in circle ( check attached image). I know how to do this in rect. But i want to make it circle. Please anyone help me in this. 回答1: Use the below code to clear circle in your context -(UIImage *) getImageWithcenterClear:(CGPoint) center{ CGRect frame = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContextWithOptions([[UIScreen mainScreen] bounds].size,

How to clear circle in CGContext in iOS

坚强是说给别人听的谎言 提交于 2020-05-26 09:09:21
问题 I want create image using CGcontext. This is simple image with white or black background. also I want to add transperent part which is in circle ( check attached image). I know how to do this in rect. But i want to make it circle. Please anyone help me in this. 回答1: Use the below code to clear circle in your context -(UIImage *) getImageWithcenterClear:(CGPoint) center{ CGRect frame = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContextWithOptions([[UIScreen mainScreen] bounds].size,

Rotate image using CGContextDrawImage

倾然丶 夕夏残阳落幕 提交于 2020-03-09 13:51:10
问题 How can I rotate an image drawn by CGContextDrawImage() at its center? In drawRect: CGContextSaveGState(c); rect = CGRectOffset(rect, -rect.size.width / 2, -rect.size.height / 2); CGContextRotateCTM(c, angle); CGContextDrawImage(c, rect, doodad.CGImage); CGContextRotateCTM(c, -angle); CGContextTranslateCTM(c, pt.x, pt.y); prevRect = rect; CGContextRestoreGState(c); I draw the image at the origin, and rotate it at its center, then translate to where it should be drawn. Not working. 回答1: The

How to draw a line between two points over an image in swift 3?

吃可爱长大的小学妹 提交于 2019-12-23 15:12:17
问题 I am new to swift, I want to draw a line between 2 points over an image which I called mapView, I tried to use CGContext but got no result, any idea to help? Thanks. UIGraphicsBeginImageContext(mapView.bounds.size) let context : CGContext = UIGraphicsGetCurrentContext()! context.addLines(between: [CGPoint(x:oldX,y:oldY), CGPoint(x:newX, y:newY)]) context.setStrokeColorSpace(CGColorSpaceCreateDeviceRGB()) context.setStrokeColor(UIColor.blue.cgColor.components!) context.setLineWidth(3) mapView?

How can I find the points in a line - Objective c?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 20:04:58
问题 Consider a line from point A (x,y) to B (p,q). The method CGContextMoveToPoint(context, x, y); moves to the point x,y and the method CGContextAddLineToPoint(context, p, q); will draw the line from point A to B. My question is, can I find the all points that the line cover? Actually I need to know the exact point which is x points before the end point B. Refer this image.. The line above is just for reference. This line may have in any angle. I needed the 5th point which is in the line before

Put border around partially transparent Image being drawn on CGContext

倾然丶 夕夏残阳落幕 提交于 2019-12-03 18:24:25
问题 I have an image with a yellow vase in the foreground and transparent background: I'm drawing it on a CGContext: CGContextDrawImage(context, CGRectMake(0, 0, 100, 100), myImage.CGImage); I can draw a shadow around it by using the following statement before CGContextDrawImage : CGContextSetShadowWithColor(context, CGSizeMake(0,0), 5, [UIColor blueColor].CGColor); But I want to put a stroke around the image, so that it'll looks like following: If I did this: CGContextSetRGBStrokeColor

iOS 8.1 crash (EXC_BAD_ACCESS) : <Error>: ImageIO: CGImageReadGetBytesAtOffset : *** ERROR *** CGImageSource was created with data size:

╄→гoц情女王★ 提交于 2019-12-02 16:04:11
问题 Appreciate any help fixing a crash (EXC_BAD_ACCESS) in my iOS app. I am seeing this since updating my app to iOS 8, using latest available iOS 8.1.2. The same code worked fine in iOS 7.x. One of the views in my app is a UICollectionView . Every cell of the collection view shows an image, which is rendered dynamically and changes after every few minutes as new content become available. The top left of the cell also shows a text label/title for that cell of the collection view. To ensure the

Alpha Detection in Layer OK on Simulator, not iPhone

↘锁芯ラ 提交于 2019-12-01 10:22:50
问题 First, check out this very handy extension to CALayer from elsewhere on SO. It helps you determine if a point in a layer's contents-assigned CGImageRef is or isn't transparent. n.b.: There is no guarantee about a layer's contents being representable or responding as if it was a CGImageRef . (This can have implications for broader use of the extension referenced above, granted.) In my case, however, I know that the layers I'm testing have contents that were assigned a CGImageRef . (Hopefully

Put border around partially transparent Image being drawn on CGContext

99封情书 提交于 2019-11-29 20:38:36
I have an image with a yellow vase in the foreground and transparent background: I'm drawing it on a CGContext: CGContextDrawImage(context, CGRectMake(0, 0, 100, 100), myImage.CGImage); I can draw a shadow around it by using the following statement before CGContextDrawImage : CGContextSetShadowWithColor(context, CGSizeMake(0,0), 5, [UIColor blueColor].CGColor); But I want to put a stroke around the image, so that it'll looks like following: If I did this: CGContextSetRGBStrokeColor(shadowContext, 0.0f, 0.0f, 1.0f, 1.0f); CGContextSetLineWidth(shadowContext, 5); CGContextStrokeRect

CGContextDrawImage is EXTREMELY slow after large UIImage drawn into it

自作多情 提交于 2019-11-28 13:52:27
问题 It seems that CGContextDrawImage(CGContextRef, CGRect, CGImageRef) performs MUCH WORSE when drawing a CGImage that was created by CoreGraphics (i.e. with CGBitmapContextCreateImage) than it does when drawing the CGImage which backs a UIImage. See this testing method: -(void)showStrangePerformanceOfCGContextDrawImage { ///Setup : Load an image and start a context: UIImage *theImage = [UIImage imageNamed:@"reallyBigImage.png"]; UIGraphicsBeginImageContext(theImage.size); CGContextRef ctxt =