Tag: 核心graphics

UIbezierpath在可缩放视图中

我在可缩放的UIView(pdf阅读器的绘图层)中绘制了bezierpaths。 当我放大文档UIView也放大,但是所有的图纸和线条看起来更像素化。 有没有办法渲染这些path没有太多的像素化? 它假设贝塞尔path是基于vector的… 提前致谢!

ios:如何用CGPath模糊图像?

我创build一个CGPath区域,如图所示的绿色圆圈。 CGPath区域需要清晰,其余的图像将被应用模糊或半透明的效果,我可以在CGPath里面用以下代码来裁剪图像: UIGraphicsBeginImageContext(view.frame.size); CGContextAddPath(ctx, path); CGContextClip(ctx); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *clipImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(clipImage, nil, nil, nil); CGPathRelease(path); 但我不知道如何同时应用CGPath模糊或半透明的效果。 我想我可以模糊原始图像,并将其与剪辑图像合并,但我不知道如何实现它。

无法在UITableViewCell的drawRect中绘制

我在绘制自定义UITableViewCell的drawRect方法时遇到了麻烦。 这是我正在使用的代码 – (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGPoint origin = _faceView.frame.origin; CGFloat width = _faceView.frame.size.width; CGFloat height = _faceView.frame.size.height; CGFloat border = 2.0f; CGPoint startPt = CGPointMake(origin.x + width/2, self.frame.size.height); CGContextBeginPath(ctx); CGContextMoveToPoint(ctx, startPt.x, startPt.y); CGPoint basePt = CGPointMake(startPt.x, origin.y – height – border); CGContextAddLineToPoint(ctx, basePt.x, basePt.y); CGRect circleRect = CGRectMake(origin.x – border, origin.y […]

正弦CAShapeLayer作为CALayer的掩码

我试图实现下一个好奇的事情:我有几个点,我想把他们与正弦波 下一个方法返回用于绘制的点arrays: – (NSArray *)plotPointsBetweenPoint:(CGPoint)pointA andPoint:(CGPoint)pointB { double H = fabs(pointB.y – pointA.y); double L = fabs(pointB.x – pointA.x); NSInteger granularity = 40; NSMutableArray *array = [NSMutableArray arrayWithCapacity:granularity + 1]; for (int i = 0; i <= granularity; ++i) { CGFloat x = M_PI*(float)i/(granularity); CGFloat y = -cosf(x); CGFloat multiplier = pointA.y > pointB.y ? […]

用静态方法在UIView(切割孔)上用清晰的颜色绘图

我有一个iPhone应用程序,我需要实现以下方法: +(UITextView *)textView:(UITextView *) withCuttedRect:(CGRect)r 这个方法必须从UITextView剪切(用[UIColor clearColor]填充)rect r并返回UITextView对象。 用户将从切割孔中看到UITextView背后的视图。 如何做呢?

用CoreGraphics在iPhone上绘制简单线条

我想在用户触摸屏幕的位置和触摸的结束点之间划一条直线。 我需要多行,因为如果用户重复触摸 – 拖放操作,我还需要一个button来清除所有的行。 到目前为止我有下面的代码,但一旦它被再次调用,我收到错误:CGContextSetStrokeColor:无效的上下文0x0。 此错误重复:CGContextBeginPath,CGContextMoveToPoint,CGContextAddLineToPoint,CGContextDrawPath。 有任何想法吗? – (void)drawRect:(CGRect)rect { c = UIGraphicsGetCurrentContext(); CGFloat black[4] = {0, 0, 0, 1}; CGContextSetStrokeColor(c, black); CGContextBeginPath(c); CGContextMoveToPoint(c, 100, 100); CGContextAddLineToPoint(c, 100, 200); CGContextStrokePath(c); }

如何在使用图像创buildvideo的同时在图像更改上添加animation

我有一个图像arrays,我想通过连续播放这些图像来创buildvideo。我想在图像变化时添加不同types的animation。 build议我使用Cocoa框架在Objective-C中实现此function的一些方法或任何解决scheme。 这里是制作图像video的工作代码,但请build议我们如何在制作video的同时制作animation图像: -(void)createVideoFromImages:(NSString *) path withSize:(CGSize) size { NSError *error = nil; AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL: [NSURL fileURLWithPath:path] fileType:AVFileTypeMPEG4 error:&error]; NSParameterAssert(videoWriter); NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt:size.width], AVVideoWidthKey, [NSNumber numberWithInt:size.height], AVVideoHeightKey, nil]; AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings]; AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput sourcePixelBufferAttributes:nil]; NSParameterAssert(videoWriterInput); NSParameterAssert([videoWriter canAddInput:videoWriterInput]); videoWriterInput.expectsMediaDataInRealTime = […]

在滚动查看中移动CALayer的蒙版

我正在尝试iOS SDK,我有以下的UIView结构: UIView UIImageView – 只有一个背景图像 UIImageView (带有CALayer掩码) UIScrollView Label 非常简单的结构, UIScrollView是透明层,第二个UIImageView有一个面具。 我想要做的是CALayer掩码将根据滚动视图中的内容的位置移动它的位置。 如果用户滚动,则应更新掩码的位置。 我已经通过使用UIScrollView的委托解决了这个问题: – (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGPoint contentOffset = scrollView.contentOffset; contentOffset.y = -contentOffset.y; self.overlayImageView.viewlayer.mask.position = contentOffset; } Mask是在viewDidLoad中创build的,在视图控制器的生命周期中不会改变。 问题是,掩码位置更新太慢。 这样,它看起来面具是跟随滚动视图的内容,而不是滚动。 scrollViewDidScroll委托方法调用正确。 为了更好地理解这个问题,我附上了一个我在iOS模拟器中制作的video。 http://www.youtube.com/watch?v=w3xRl3LTngY 所以问题是: 有没有办法让面具更新更快,或者这是iOS的限制?

如何用特定的颜色绘制CGGradient?

我有这个我find的这个Objective-C代码。 老实说,我不明白在那里发生的一件事情。 我根本不熟悉Core Graphics。 下面的代码表示左边的图像。 我想要的是一个类似的颜色渐变到右边的图像(所需的颜色有12,138,255的RGB)。 我在哪里改变这个代码来获得所需的结果? – (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGSize titleSize = [croppedTitle sizeWithFont:kTokenTitleFont]; CGRect bounds = CGRectMake(0, 0, titleSize.width + 17, titleSize.height + 5); CGRect textBounds = bounds; textBounds.origin.x = (bounds.size.width – titleSize.width) / 2; textBounds.origin.y += 4; CGFloat arcValue = (bounds.size.height / 2) + 1; CGColorSpaceRef colorspace = […]

iOS:逆UIBezierPath(bezierPathWithOvalInRect)

我有一个圆形对象的JPG图像矩形,并希望使圆形对象的透明度… (在这个例子中删除红色区域) 在这个iOS的帮助下, 使UIImage透明和“UIBezierPath bezierPathWithOvalInRect”的一部分,我已经取得了一些成功,但是这使得我的对象周围的道路,我需要倒过来,使外部而不是内部path透明.. 我不知道我必须改变我的代码才能得到正确的结果.. 这是我的代码: //BezierPath UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)]; // Create an image context containing the original UIImage. UIGraphicsBeginImageContext(_imgTemp.image.size); [_imgTemp.image drawAtPoint:CGPointZero]; // Clip to the bezier path and clear that portion of the image. CGContextRef context = UIGraphicsGetCurrentContext(); CGContextAddPath(context,bezierPath.CGPath); CGContextClip(context); CGContextClearRect(context,CGRectMake(0,0,self._imgTemp.image.size.width,self._imgTemp.image.size.height)); // Build a new UIImage from the […]