首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSBezierPath图

NSBezierPath图
EN

Stack Overflow用户
提问于 2012-01-28 21:05:13
回答 1查看 684关注 0票数 3

我不知道如何优化包含NSBezierPath的NSView的绘图。

让我试着解释一下我的意思。我有一个线形图,由大约40K个点组成,我想画它。我有所有的点,我很容易使用下面的代码来绘制完整的图形:

代码语言:javascript
复制
NSInteger npoints=[delegate returnNumOfPoints:self]; //get the total number of points
aRange=NSMakeRange(0, npoints); //set the range
absMin=[delegate getMinForGraph:self inRange:aRange]; //get the Minimum y value
absMax=[delegate getMaxForGraph:self inRange:aRange]; //get the Maximum y value
float delta=absMax-absMin;  //get the height of bound
float aspectRatio=self.frame.size.width/self.frame.size.heigh //compensate for the real frame
float xscale=aspectRatio*(absMax-absMin); // get the width of bound
float step=xscale/npoints; //get the unit size
[self setBounds:NSMakeRect(0.0, absMin, xscale, delta)]; //now I can set the bound
NSSize unitSize={1.0,1.0};
unitSize= [self convertSize:unitSize fromView:nil];
[NSBezierPath setDefaultLineWidth:MIN(unitSize.height,unitSize.width)];
fullGraph=[NSBezierPath bezierPath];
[fullGraph moveToPoint:NSMakePoint(0.0, [delegate getValueForGraph:self forPoint:aRange.location])];
//Create the path
for (long i=1; i<npoints; i++)
    {
        y=[delegate getValueForGraph:self forPoint:i];
        x=i*step;
        [fullGraph lineToPoint:NSMakePoint(x,y)];
}
[[NSColor redColor] set];
[fullGraph stroke];

现在,我将整个图形存储在一个NSBezierPath格式的实坐标中,这样我就可以进行描边了。但让我们假设现在我想要显示图形,尽可能快地一次添加一个点。

我不想每次都绘制一整套的点。我想使用,如果可能的话,完整的图表和可视化只有一小部分。假设我只想在同一帧中渲染前1000个点。有没有可能(修改边界并最终以某种方式缩放路径)在正确的边界中只渲染图形的第一部分?

我无法得到结果,因为如果我修改了边界,那么比例就会改变,并且我无法解决线宽的问题。

EN

回答 1

Stack Overflow用户

发布于 2012-01-28 23:35:32

您可以仅使用新数据创建新路径,对其进行描边,然后将其附加到现有图形中:

代码语言:javascript
复制
NSBezierPath* newPath = [NSBezierPath bezierPath];
//... draw the new lines in newPath ...
[newPath stroke];
[fullGraph appendBezierPath:newPath];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9045439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档