我不知道如何优化包含NSBezierPath的NSView的绘图。
让我试着解释一下我的意思。我有一个线形图,由大约40K个点组成,我想画它。我有所有的点,我很容易使用下面的代码来绘制完整的图形:
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个点。有没有可能(修改边界并最终以某种方式缩放路径)在正确的边界中只渲染图形的第一部分?
我无法得到结果,因为如果我修改了边界,那么比例就会改变,并且我无法解决线宽的问题。
发布于 2012-01-28 23:35:32
您可以仅使用新数据创建新路径,对其进行描边,然后将其附加到现有图形中:
NSBezierPath* newPath = [NSBezierPath bezierPath];
//... draw the new lines in newPath ...
[newPath stroke];
[fullGraph appendBezierPath:newPath];https://stackoverflow.com/questions/9045439
复制相似问题