Tag: 绘制

在iPhone中使用OpenGL ES绘制直线?

最后,我试图在XCode 4.2中使用OpenGL ES框架为iPhone简单的游戏app.I研究了一些关于GLKView和GLKViewController在iPhone中绘制一条线。 这是我在我的项目中尝试过的示例代码, @synthesize context = _context; @synthesize effect = _effect; – (void)viewDidLoad { [super viewDidLoad]; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; if (!self.context) { NSLog(@"Failed to create ES context"); } GLKView *view = (GLKView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; [EAGLContext setCurrentContext:self.context]; //[self setupGL]; } – (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { NSLog(@"DrawInRect Method"); [EAGLContext […]

有没有一个SDK在iOS上用触摸画线?

有没有我可以用来画线的框架。 基本上我想增加客户在iPad / iPhone上login并将其作为图像进行捕捉的能力。 任何帮助非常感谢。 谢谢。

滞后,而在ios7绘图

我有一个应用程序,我正在做一些视图草图。 到目前为止,它工作正常,直到我安装了ios7 。 我的应用程序使用触摸移动的方法来识别运动的变化。 但是,当我画一条线,触摸方法被调用,但行不会更新,直到我触摸结束在ios7 。 所以绘图有一点点滞后。 它在ios6和ios7模拟器上工作正常,但是当我在真正的ios7设备上testing时,绘图algorithm存在滞后性。 – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (!isImageSelection) { mouseSwiped = NO; UITouch *touch = [touches anyObject]; if ( [touch view] != baseview) { lastPoint2 = [touch locationInView:self.viewDrawing2]; } } } – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (!isImageSelection) { // NSLog(@"in image selection==%d touch moved ",isImageSelection […]

如何用Core Graphics / iPhone绘制渐变弧线?

我知道如何绘制弧线 我也发现如何从这里画出一条渐变线 我发现两个函数可以绘制渐变:CGContextDrawLinearGradient和CGContextDrawRadialGradient.but我怎样才能绘制一个渐变圆弧? 我想要实现这样的画面:

UIBezierPath笔画1px线和填充1px宽的矩形 – 不同的结果。

这是一个简单的绘图 – (void)drawRect:(CGRect)rect { //vertical line with 1 px stroking UIBezierPath *vertLine = [[UIBezierPath alloc] init]; [vertLine moveToPoint:CGPointMake(20.0, 10.0)]; [vertLine addLineToPoint:CGPointMake(20.0, 400.0)]; vertLine.lineWidth = 1.0; [[UIColor blackColor] setStroke]; [vertLine stroke]; //vertical rectangle 1px width UIBezierPath *vertRect= [UIBezierPath bezierPathWithRect:CGRectMake(40.0, 10.0, 1.0, 390.0)]; [[UIColor blackColor] setFill]; [vertRect fill]; } 在非视网膜3GS和模拟器的第一行是模糊的,看起来比1像素宽,但第二行是脆。 不幸的是我没有iPhone4和新的iPadtesting,但在视网膜模拟器上,两条线看起来都是一样的。 问题:矩形而不是中风是获得非视网膜和视网膜设备相同结果的唯一方法?

如何使用drawRect绘制现有的视图?

我正在做一个GPS跟踪应用程序。 每次它接收到经度/纬度时,都会将其转换为(x,y)坐标,并调用drawRect在两个(x,y)对之间绘制一条直线。 然而,drawRect方法在绘制新东西之前只清除所有的旧内容。 如何让drawRect在现有的canvas上绘制新的东西? 提前致谢 这里是我的viewController.h #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @class routetrack; @interface simpleDrawViewController : UIViewController <CLLocationManagerDelegate> { CLLocationManager *locationManager; IBOutlet routetrack *routeroute; float latOld; float longOld; float latNew; float longNew; } – (IBAction) gpsValueChanged; @property (nonatomic,retain) CLLocationManager *locationManager; @property (retain,nonatomic) routetrack *routeroute; ViewController.m #import "simpleDrawViewController.h" #import "routetrack.h" @implementation simpleDrawViewController @synthesize locationManager,btn,routeroute; – (IBAction) gpsValueChanged{ […]

在UIScrollView的子视图中绘制一个网格分配巨大的内存

我试图在UIScrollView中创build一个UIView,其中只包含一个由UIBezierPath或使用CG函数淹没的简单网格(行为行和列)。 问题是,当我有更大的内容大小的UIScrollView(以及更大的子视图),在绘制网格时,分配了大量的内存(50MB或更多)。 UIViewController其中包括整个场景只是UIScrollView – 在viewDidLoad中添加子视图: @interface TTTTestViewController() @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @end @implementation TTTTestViewController -(void)viewDidLoad { [super viewDidLoad]; // create the subview TTTTestView *testView = [[TTTTestView alloc] init]; [self.scrollView addSubview:testView]; //set its properties testView.cellSize = 50; testView.size = 40; // set the content size and frame of testView by the properties self.scrollView.contentSize = […]

围绕UIImageView的内容绘制边框

我有一个UIImageView与图像是一个透明背景的汽车: 我想在车上画一个边框: 我怎样才能达到这个效果? 目前,我已经用这种方式testing了CoreGraphics,但没有好的结果: // load the image UIImage *img = carImage; UIGraphicsBeginImageContext(img.size); CGContextRef context = UIGraphicsGetCurrentContext(); [[UIColor redColor] setFill]; CGContextTranslateCTM(context, 0, img.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextSetBlendMode(context, kCGBlendModeNormal); CGRect rect = CGRectMake(0, 0, img.size.width * 1.1, img.size.height*1.1); CGContextDrawImage(context, rect, img.CGImage); CGContextClipToMask(context, rect, img.CGImage); CGContextAddRect(context, rect); CGContextDrawPath(context,kCGPathFill); // generate a new UIImage from the graphics context […]

在iOS中沿着path均匀地绘制图像

我想要做的就是在屏幕上移动我的手指(touchesMoved)并沿touchesMoved生成的点绘制均匀间隔的图像(可能是CGImageRefs)。 我可以画线,但是我想要生成的东西看起来像这样(对于这个例子,我使用的是一个箭头的图像,但它可能是任何图像,可能是我的狗的图片:))主要的是当用iPhone或iPad上的手指进行绘图时,图像均匀分布。

用CoreGraphics绘制半圆

我知道如何用CGPath绘制线条和形状。 但我不知道如何绘制这个符号的电路图 我应该写什么代码来获得半圆形状? 这是我迄今为止: – (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 5.0); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGContextMoveToPoint(context, 60, 80); CGContextAddLineToPoint(context, 120, 80); CGContextMoveToPoint(context, 120, 80); CGContextAddArc(120,80,M_PI,M_PI/2); CGContextMoveToPoint(context, 200, 80); CGContextAddLineToPoint(context, 300, 80); CGContextStrokePath(context); }