Tag: 核心graphics

在视图周围绘制阴影会减慢我的过渡,CALayer,ios

MyViewControllerB.xib包含 view( UIView ) | |__image (UIImageView) | |__view (UIView) | |__text (UITextView) | |__view (UIView) ( shadow is adding at here ) 然后我在底部的视图周围添加一个阴影如下 – (void)viewDidLoad { [super viewDidLoad]; [self.bottomView.layer setMasksToBounds:NO]; self.bottomView.layer.shadowColor = [UIColor blackColor].CGColor; self.bottomView.layer.shadowRadius = 5; self.bottomView.layer.shadowOpacity = 1; self.bottomView.layer.shadowOffset = CGSizeMake(0 , 0 ); } 当我做pushViewController: animated:在MyViewControllerA: @implementation MyViewControllerA MyViewControllerB *controller = […]

在Quartz2D中使用UIImage或UILabel或NSString是否有任何性能或内存开销?

在Quartz2D使用UIImage或UILabel或NSString是否有任何性能或内存开销? 如果没有区别,那么为什么不使用UIImage , UILabel等 可以任何一个给我的片段如何绘制图像,而不使用UIImage 。 在此先感谢,关心。 请纠正我,如果你看到我对这个新的愚蠢的错误,试图学习它。

使用UIGraphicsGetImageFromCurrentImageContext时正确的GraphicsContext

我有以下方法,我试图做一些绘图到一个图像: – (UIImage*) renderImage { UIGraphicsBeginImageContextWithOptions(self.size, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); //drawing code UIImage *image = [UIGraphicsGetImageFromCurrentImageContext() retain]; UIGraphicsEndImageContext(); return [image autorelease]; } 当我运行这段代码的时候,我注意到,比起我在UIView drawRect中简单绘制代码的时候,我受到的打击要困难得多。 我在这里绘制到错误的graphics上下文(即CGContextRef context = UIGraphicsGetCurrentContext(); )? 或者是UIGraphicsGetImageFromCurrentImageContext只是比绘制drawRect更昂贵?

内存问题与CGlayer

我正在绘制CGlayers。 我已经实现了绘图部分,用户绘制的drawingView(canvas)是dynamic的,我的意思是用户可以增加/减lessdrawingView(Canvas)的高度, 例如默认大小 – 500 * 200 当用户点击扩展button – 500 * 300 所以这里是我的function,当用户扩大canvas, – (void)IncreaseCanavasSize { CGContextRef layerContext1 = CGLayerGetContext(permanentDrawingLayer ); CGContextDrawLayerInRect(layerContext1, rectSize, newDrawingLayer); rectSize = self.bounds; CGFloat scale = self.contentScaleFactor; CGRect bounds = CGRectMake(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale); CGLayerRef layer = CGLayerCreateWithContext(layerContext1, bounds.size, NULL); CGContextRef layerContext = CGLayerGetContext(layer); CGContextScaleCTM(layerContext, scale, scale); […]

镜像UIView

我有一个透明背景的UIView和一些button。 我想捕捉视图的graphics,缩小它,并重画(镜像)在屏幕上的其他地方。 (在另一个视图之上。)button可以改变,所以它不是静态的。 什么是最好的方法来做到这一点?

非循环发光的CGContextDrawRadialGradient

我能够使用CGContextDrawRadialGradient来做一个阿尔法淡入UIColor.clearColor的球体,它的工作原理。 不过,我正在尝试做这样的事情: 虽然放置一些战略领域使得一个有趣的效果(类似于战略地点的LED背光),我很想得到真正的光芒。 如何在drawRect围绕圆angular矩形绘制光晕?

imageWithCGImage:GCD内存问题

当我只在主线程执行以下操作时, iref立即获得autoreleased: -(void)loadImage:(ALAsset*)asset{ @autoreleasepool { ALAssetRepresentation* rep = [asset defaultRepresentation]; CGImageRef iref = [rep fullScreenImage]; UIImage* image = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:UIImageOrientationUp]; [self.imageView setImage:image]; } } 但是当我执行imageWithCGImage时:在后台线程上使用GCD iref不会像第一个例子那样立即被释放。 只有一分钟后: -(void)loadImage:(ALAsset*)asset{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { @autoreleasepool { ALAssetRepresentation* rep = [asset defaultRepresentation]; CGImageRef iref = [rep fullScreenImage]; UIImage* image = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:UIImageOrientationUp]; […]

为什么我的Coregraphics绘图代码造成滞后?

我正在为iPhone绘制应用程序。 它在iPhone模拟器的5秒内工作正常,但随着越来越多,我得出它更加滞后。 当我在设备上testing时,它会变得更加迟钝,我甚至无法画出一棵简单的树。 当我检查处理器在xcode上的运行百分比时,通常在97-100%之间。 有没有什么办法解决这一问题? (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; currentPoint = [touch locationInView:self.view]; UIGraphicsBeginImageContext(CGSizeMake(320, 568)); [drawImage.image drawInRect:CGRectMake(0, 0, 320, 568)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 1, 0, 1); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGPathMoveToPoint(path, NULL, lastPoint.x, lastPoint.y); CGPathAddLineToPoint(path, NULL, currentPoint.x, currentPoint.y); CGContextAddPath(UIGraphicsGetCurrentContext(),path); CGContextStrokePath(UIGraphicsGetCurrentContext()); [drawImage setFrame:CGRectMake(0, 0, 320, 568)]; drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); […]

CALayer使用对angular虚线渲染问题

我使用下面的代码创build了一个虚线的CAShapeLayer 。 当它的path在完全水平的平面上时,线条正确绘制。 然而,只要path上下移动,线路就会遇到一些问题。 以图像为例。 CGMutablePathRef linePath = CGPathCreateMutable(); CGPathMoveToPoint(linePath, NULL, startShapeLayer.centerX, startShapeLayer.centerY); CGPathAddLineToPoint(linePath, NULL, endShapeCenter.x, endShapeCenter.y); CGPathCloseSubpath(linePath); CAShapeLayer *lineLayer = [CAShapeLayer layer]; lineLayer.path = linePath; lineLayer.fillColor = [UIColor clearColor].CGColor; lineLayer.strokeColor = [UIColor whiteColor].CGColor; lineLayer.lineCap = kCALineCapRound; lineLayer.lineDashPattern = @[@5, @5]; lineLayer.lineDashPhase = 5.0; lineLayer.lineWidth = 1.0; 如果任何人有关于绘制这些形状的build议,这将是非常好的听到。

NSString drawInRect:并在iOS上放置阴影

我正在使用[NSString drawInRect:]绘制文本到纹理,一切正常,直到我添加阴影。 它们看起来是正确的,但是经常被我正在绘制的矩形裁剪。 问题是[NSString sizeWithFont:]不知道下拉阴影,因为它们是通过CGContextSetShadowWithColor(…) 。 这里是我使用的代码(去除绒毛): CGSize dim = [theString sizeWithFont:uifont]; … CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f); CGContextTranslateCTM(context, 0.0f, dim.height); CGContextScaleCTM(context, 1.0f, -1.0f); CGContextSetShadowWithColor(context, CGSizeMake(dropOffset.x, dropOffset.y), dropBlur, dropColorRef); … [theString drawInRect:dim withFont:uifont lineBreakMode:UILineBreakModeWordWrap alignment:align]; 我已经尝试了扩展dim ,把阴影和模糊考虑在内,这主要是工作,但有时扩展矩形导致线被完全不同,由于额外的空间被添加。 有没有更好的方法来find绘制(或绘制string)所需的纹理/矩形的大小比我使用?