Tag: 核心graphics

如何使用CGAffineTransformMakeRotation?

我想绘制文本使用Quartz 2D。 “菜单”方向是错误的。 我想“菜单”仍然可读,并与X轴有45度。 以下是我的代码: CGContextSelectFont(context, "Arial", 12, kCGEncodingMacRoman); CGContextSetTextDrawingMode(context, kCGTextFill); CGContextSetRGBFillColor(context, 0, 0, 0, 1); // 6 CGContextSetRGBStrokeColor(context, 0, 0, 0, 1); CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0)); CGContextSetTextMatrix(context, CGAffineTransformMakeRotation(45)); CGContextShowTextAtPoint(context,10, 10, "Menu", 4);

两个CGPath / UIBeziers之间的补间/插补

我有一个包含CGPath的CAShapeLayer。 使用iOS的内置animation,我可以使用animation轻松地将此path变形为另一个: CABasicAnimation *morph = [CABasicAnimation animationWithKeyPath:@"path"]; morph.fromValue = (id)myLayer.path; mayLayer.path = [self getNewPath]; morph.toValue = (id)myLayer.path; morph.duration = 0.3; [myLayer addAnimation:morph forKey:nil]; 这是完美的。 但是,现在我想在拖动操作期间逐渐在这些path之间变形。 为了做到这一点,我需要能够在拖动过程中的任何点检索插入的path。 有没有办法问这个iOS?

ARC是否与Core Graphics对象一起工作?

我最近开始使用自动引用计数(ARC)的新项目。 当我分配CALayer的内容时: UIView* view = … UIImage* image = … view.layer.contents = image.CGImage 我有一个错误 ARC不允许将非Objective-C指针types“CGImageRef”隐式转换为“id” 简单地把CGImageRef成id隐藏了这个错误,但是我想知道ARC是否仍然正常工作呢?

我怎样才能设置CG_CONTEXT_SHOW_BACKTRACE环境variables?

在我看来,我有三个button。 在viewDidLoad()中设置了cornerRadus后: button.layer.cornerRadius = 20我在日志中得到以下错误信息: <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. 问题: 我怎样才能设置CG_CONTEXT_SHOW_BACKTRACE环境variables? 或者我该如何解决这个警告? 好吧,我现在从消息中回溯。 这对我没有任何意义。 一些帮助,请… Aug 7 14:27:00 <Error>: CGContextSaveGState: invalid context 0x0. Backtrace: <-[UIStatusBarItemView updateContentsAndWidth]+33> <-[UIStatusBarItemView initWithItem:data:actions:style:]+477> <+[UIStatusBarItemView createViewForItem:withData:actions:foregroundStyle:]+134> <-[UIStatusBarLayoutManager _createViewForItem:withData:actions:]+163> <-[UIStatusBarLayoutManager _prepareEnabledItemType:withEnabledItems:withData:actions:itemAppearing:itemDisappearing:]+36 <-[UIStatusBarLayoutManager prepareEnabledItems:withData:actions:]+92> <-[UIStatusBarForegroundView _setStatusBarData:actions:animated:]+797> <-[UIStatusBarForegroundView setStatusBarData:actions:animated:]+332> <__51-[UIStatusBar _prepareToSetStyle:animation:forced:]_block_invoke+360> […]

从圆圈或圆环画出细分

我一直在试图找出一种方法来绘制段如下图所示: 我想: 绘制段 包括渐变 包括阴影 从0到n的angular度animation绘图 我一直在尝试使用CGContextAddArc和类似的调用来做到这一点,但没有得到很大的进展。 谁能帮忙?

如何缩小UIImage,使其变得脆弱/锐利,而不是模糊?

我需要缩小一幅图像,但要锐利。 在Photoshop中,例如,图像尺寸缩小选项“Bicubic Smoother”(模糊)和“Bicubic Sharper”。 这个图像缩小algorithm是开源还是在某个地方logging,或者SDK是否提供了这样的方法?

调整高宽比的UIImage?

我使用这段代码来调整iPhone上的图像大小: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:kCGBlendModePlusDarker alpha:1]; UIImage *tmpValue = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 只要图像的宽高比与新resize的图像的高宽比相匹配,哪个效果很好。 我想修改这个,以保持正确的长宽比,只是在图像没有出现的地方放一个黑色的背景。 所以我仍然会得到一个320×480的图像,但在顶部和底部或侧面有黑色,这取决于原始图像的大小。 有没有一种简单的方法来做到这一点类似于我在做什么? 谢谢!