cgcontext

How to use NSString's sizeWithFont and drawInRect to workout how much of a string to draw

泄露秘密 提交于 2019-11-30 05:31:40
I'm drawing multiple 'pages' of imagery using a CGContext in the iOS. I've used sizeWithFont and drawInRect combinations extensively in my app. What I need to do is split a large chunk of text across multiple pages. I can size it and work out whether or not it needs another page but how do I know where to chop it? Do I have to do an ugly loop to check word by word until I find a string length that perfectly fits the page and then chop the string at that point? Is there a smarter way? Any ideas? Thanks. The NSString additions to UIKit for drawing text, you can pre-determine the exact amount of

Draw a simple circle uiimage

非 Y 不嫁゛ 提交于 2019-11-30 03:11:04
I try to make a 20x20 UIImage with a simple blue circle. I try with this function, but the result is a blue circle in a black square. How do I remove the black square around the circle? Function: + (UIImage *)blueCircle { static UIImage *blueCircle = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ UIGraphicsBeginImageContextWithOptions(CGSizeMake(20.f, 20.f), YES, 0.0f); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSaveGState(ctx); CGRect rect = CGRectMake(0, 0, 20, 20); CGContextSetFillColorWithColor(ctx, [UIColor cyanColor].CGColor);

UISearchBar CGContext ERROR

老子叫甜甜 提交于 2019-11-29 22:47:41
I have a UISearchBar inside a view, whenever I tap on it, after the keyboard comes up - after -(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar it sends this to the console: <Error>: CGContextSetStrokeColorWithColor : invalid context 0x0 . This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. It repeats the same error. I am wonderring what exactly could

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

Saving and restoring CGContext

与世无争的帅哥 提交于 2019-11-29 18:34:20
问题 I'm trying to save and restore a CGContext to avoid doing heavy drawing computations for a second time and I'm getting the error <Error>: CGGStackRestore: gstack underflow . What am I doing wrong? What is the correct way to do this? - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); if (initialized) { CGContextRestoreGState(context); //scale context return; } initialized = YES; //heavy drawing computation and drawing CGContextSaveGState(context); } 回答1: I

CGContextSaveGState vs UIGraphicsPushContext

隐身守侯 提交于 2019-11-29 16:51:03
问题 There are two drawRect methods: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); // do drawing here CGContextRestoreGState(context); } And - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); UIGraphicsPushContext(context); // do drawing here UIGraphicsPopContext(); } UIGraphicsPushContext / UIGraphicsPopContext are from UIKit while CGContextSaveGState / CGContextRestoreGState are from

drawInRect: losing Quality of Image resolution

与世无争的帅哥 提交于 2019-11-29 16:49:39
问题 I am trying to erase image using following code CGColorRef strokeColor = [UIColor whiteColor].CGColor; UIGraphicsBeginImageContext(imgForeground.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); [imgForeground.image drawInRect:CGRectMake(0, 0, imgForeground.frame.size.width, imgForeground.frame.size.height)]; CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineWidth(context, 10); CGContextSetStrokeColorWithColor(context, strokeColor); CGContextSetBlendMode(context,

Drawing in CATiledLayer with CoreGraphics CGContextDrawImage

廉价感情. 提交于 2019-11-29 14:55:16
问题 I would like to use a CATiledLayer in iPhone OS 3.1.3 and to do so all drawing in -(void)drawLayer:(CALayer *)layer inContext:(CGContext)context has to be done with coregraphics only. Now I run into the problems of the flipped coordinate system on the iPhone and there are some suggestions how to fix it using transforms: Image is drawn upside down CATiledLayer or CALayer not working My problem is that I cannot get it to work. I started using the PhotoScroller sample code and replacing the

Merging a previosly rotated by gesture UIImageView with another one. WYS is not WYG

≡放荡痞女 提交于 2019-11-29 10:28:39
问题 I'm getting crazy while trying to merge two UIImageView. The situation: a background UIImageView (userPhotoImageView) an overlayed UIImageView (productPhotoImageView) that can be streched, pinched and rotated I call my function on the UIImages but I can take coords and new stretched size from the UIImageView containing them (they are synthesized in my class) - (UIImage *)mergeImage:(UIImage *)bottomImg withImage:(UIImage *)topImg; Maybe simplest way would be rendering the layer of the top

CGContext vs CALayer

爷,独闯天下 提交于 2019-11-29 10:18:51
问题 I'm trying to get a handle on Quartz 2D and looking at the online book Quartz 2D Graphics for Mac OS X Developers. One very basic thing that is confusing me is the CGContext. For example, I can draw a simple "U" shape with the code below and use it in a CAShapeLayer without referencing a CGContext . Is the context implied/provided by default by the CAShapeLayer ? I'm probably mixing up several iOS/OSX graphics APIs here so maybe someone can clarify where I am going wrong. CGPoint pt1 =