Tag: cgcontext

画一个CGlayer到另一个CGlayer

我使用两个CGlayers进行绘制,Layer1和Layer2,我绘制到Layer1和触摸结束,我将数据转移到Layer2,并清除Layer1,并在我的drawRect,方法,我画两个层的上下文。 点击删除button,我将绘图从Layer2转移到Layer1,然后我删除layer1,但触摸结束,我不转移到Layer2,因为我只擦除Layer1 在笔上点击如果擦除发生,我将绘图从Layer1转移到Layer2,否则以前的绘图可能会消失。 在代码中,它的样子 – (void)eraserButtonClicked { CGContextRef layerContext1 = CGLayerGetContext( self.layer1); CGContextClearRect(layerContext1, self.bounds); CGContextDrawLayerInRect(layerContext1, self.bounds, self.layer2); CGContextRef layerContext = CGLayerGetContext(self.layer2 ); CGContextClearRect(layerContext, self.bounds); } – (void)pen1ButtonClicked { CGContextRef layerContext = CGLayerGetContext(self.layer2 ); CGContextClearRect(layerContext, self.bounds); CGContextDrawLayerInRect(layerContext, self.bounds, self.layer1); CGContextRef layerContext1 = CGLayerGetContext( self.layer1); CGContextClearRect(layerContext1, self.bounds); } 所以我把这个图层从一个图层转移到另一个图层,但是会发生什么 1)如果我画一条线,那么我点击擦除button,然后不擦除,如果我再次点击笔画,并没有画任何东西,如果我再次点击擦除button,现在当我试图擦除整个绘图消失 2)但是,如果我画线,然后点击擦除button,并删除线,然后再转移到笔button,画一条线,再次转到擦除button,并尝试擦除,它完美的工作。

UITableViewCells尝试绘制无效上下文

我想在UITableViewCell中绘制一个checkbox三angular形。 在数据源协议方法-tableView:cellForRowAtIndexPath:我已经在代码块中添加了以下内容,询问单元格是否为零: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextBeginPath(context); CGContextMoveToPoint(context, 75,10); CGContextAddLineToPoint(context, 10, 150); CGContextAddLineToPoint(context, 160, 150); CGContextClosePath(context); [[UIColor blackColor] setStroke]; CGContextStrokePath(context); 执行代码时,我得到了一系列'无效的上下文0x0'消息在以下方法:CGContextBeginPath:CGContextMoveToPoint:CGContextAddLineToPoint:(两次)CGContextClosePath:CGContextSetStrokeColorWithColor:CGContextDrawPath 消息重复我的表中的每个TableViewCell行。 我无法在customizedUITableViewCell对象内绘制三angular形或其他几何形状吗?

是否有可能从uview中获得所有uibezerpath?

我一直在研究,没有find答案。 如果我使用CGGontext绘制到视图,是否有可能从UIView一次绘制UIView所有的UIBezierPath? (如果是的话,你可以给我一个想法如何?)UIBezierPath来自用户input,所以如果用户绘制了很多UIBezierPath,我需要所有这些path,并将其保存到.svg文件。

从CIImage转换它后UIImage横向

我在UIImage应用filter,但转换后,它显示为侧面。 以下是我的代码。 CIImage *ciImage = [[CIImage alloc] initWithImage:self.imgToProcess]; CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectChrome" keysAndValues:kCIInputImageKey, ciImage, nil]; [filter setDefaults]; CIContext *context = [CIContext contextWithOptions:nil]; CIImage *outputImage = [filter outputImage]; CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]]; UIImage *newImage = [[UIImage alloc]initWithCIImage:outputImage]; 它在newImage和尺寸中成功呈现,但图像是侧面的。 上面的代码中有没有导致方向改变的地方?

如何使用CGContext iOS在其他设备方向绘制string

我试图在iPhone上绘制一些文本,但是在横向模式下,主页button位于左侧。 所以我需要以某种方式扭转数字(我猜我使用了一个转换)? 这是我现在拥有的: CGContextSetRGBFillColor(context, 1.0, 0, 0, 1.0); CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman); CGContextSetTextMatrix(context, CGAffineTransformMakeRotation(M_PI/2)); CGContextSetTextDrawingMode(context, kCGTextFill); NSString *t = [NSString stringWithFormat:@"%i",seconds]; const char *str=[t UTF8String]; CGContextShowTextAtPoint(context,6.0,15.0,str,strlen(str)); 我需要添加什么来旋转文本,以便在手机左侧的homebutton处于横向时可以阅读文本。

从UIImage中删除Alpha通道

我使用以下方法从文件系统中获取解压缩的uiimage。 但是,当打开颜色混合图层时,即使将UIImageView设置为“不透明”,UIImageView也会显示为红色。 文件系统上的图像没有alpha通道。 我试过设置CGContextSetAlpha(bitmapContext,1),但仍然有混合层。 任何人都知道如何使用CGContextDrawImage删除alpha通道? – (UIImage *)decompressedImage { CGImageRef imageRef = self.CGImage; CGRect rect = CGRectMake(0.f, 0.f, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)); CGContextRef bitmapContext = CGBitmapContextCreate(NULL, rect.size.width, rect.size.height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), CGImageGetColorSpace(imageRef), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little ); // kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little are the bit flags required // so that the main thread doesn't have any conversions to do. CGContextDrawImage(bitmapContext, […]

如何使用Core Graphics在我的触摸位置绘制一个圆圈?

新的程序员在这里。 我在尝试使用Core Graphics在我的触摸位置周围绘制描边弧时出现问题。 我有方法来绘制圆圈工作正常,我已经testing,并正在注册触摸,当我点击屏幕,但是当我尝试调用方法来绘制圆时,我点击,我得到错误“CG​​ContextBlahBlah:invalid context为0x0" 我认为这是因为我没有在drawRect :()中调用方法。 那么我怎么能够通过触摸来调用这个方法呢? 另外,如何在我的绘图方法中使用“CGPoint locationOfTouch”作为参数? 这是我正在使用的代码块。 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint locationOfTouch = [touch locationInView:self]; [self drawTouchCircle:(locationOfTouch)]; [self setNeedsDisplay]; } -(void)drawTouchCircle:(CGPoint)locationOfTouch { CGContextRef ctx= UIGraphicsGetCurrentContext(); CGContextSaveGState(ctx); CGContextSetLineWidth(ctx,5); CGContextSetRGBStrokeColor(ctx,0.8,0.8,0.8,1.0); CGContextAddArc(ctx,locationOfTouch.x,locationOfTouch.y,30,0.0,M_PI*2,YES); CGContextStrokePath(ctx); } 先谢谢您的帮助!

CGBitmapContextCreate:不受支持的参数组合

我正在尝试创build一个8位灰度上下文,如下所示: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); CGContextRef context = CGBitmapContextCreate( data, m_width, m_height, 8, m_width, colorSpace, kCGBitmapByteOrder32Little|kCGImageAlphaNone); 但是我有以下错误: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 8 bits/pixel; 1-component color space; kCGImageAlphaNone; 1936 bytes/row. 为什么这个组合不受支持?

如何将UIView渲染成CGContext

我想要渲染一个UIView到CGContextRef -(void)methodName:(CGContextRef)ctx { UIView *someView = [[UIView alloc] init]; MagicalFunction(ctx, someView); } 所以,这里的MagicalFunction应该把UIView(可能是它的图层)渲染到当前的上下文中。 我怎么做? 提前致谢!

显示操作表导致CGContext无效的上下文错误

我正在使用操作表来显示供用户select的数据列表。 问题是显示使用[self.actionSheet showInView:self.view]; 导致几个CGContext错误。 相同的代码在iOS 6中运行良好。 码: self.actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; [self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque]; CGRect tableFrame = CGRectMake(0, 40, 320, 214); self.tableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain]; self.tableView.dataSource = self; self.tableView.delegate = self; [self.actionSheet addSubview:self.tableView]; UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]]; closeButton.momentary = YES; closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); […]