如何从 CPTPlotSymbol 创建 UIImage?
How to create UIImage from CPTPlotSymbol?
我是 Core-Plot
的新手,这是我的问题。
我使用 ScatterPlot
class 创建了我的 Graph
。而我的绘图符号创建数据源方法是:
- (CPTPlotSymbol*)symbolForScatterPlot:(CPTScatterPlot *)plot recordIndex:(NSUInteger)index
{
CPTPlotSymbol *symbol = [[CPTPlotSymbol alloc]init];
if (index %2 == 0)
{
symbol.symbolType = CPTPlotSymbolTypeDiamond;
symbol.fill = [CPTFill fillWithColor:[CPTColor redColor]];
symbol.size = CGSizeMake(10, 10);
return symbol;
}
else
{
symbol.symbolType = CPTPlotSymbolTypeEllipse;
symbol.fill = [CPTFill fillWithColor:[CPTColor orangeColor]];
symbol.size = CGSizeMake(15, 15);
return symbol;
}
}
并且当我 select 我的 scatter plot
中的任何绘图符号时,我想将那个 selected 绘图符号转换为 UIImage
,因为在转换成图像后我想要将图像从源位置拖到任何其他地方plotspace
。
我实现了委托方法从我的散点图中获取 selected 绘图符号,代码是
- (void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
CPTPlotSymbol *selectedSymbol = [plot plotSymbolForRecordIndex:index];
NSLog(@"%@", selectedSymbol);
}
从上面的代码中,我得到了我的 selected 绘图符号对象。但从这里我不知道如何将这个绘图符号对象转换为 UIImage
。如果有人指导我,那就太好了,或者有任何其他更好的方法来解决我的问题意味着也请以这种方式帮助我。提前致谢
您可以使用-renderAsVectorInContext:atPoint:scale:
方法将符号绘制成CGContext
。创建上下文,将符号绘制到其中,并使用UIGraphicsGetImageFromCurrentImageContext()
创建一个UIImage
。
我是 Core-Plot
的新手,这是我的问题。
我使用 ScatterPlot
class 创建了我的 Graph
。而我的绘图符号创建数据源方法是:
- (CPTPlotSymbol*)symbolForScatterPlot:(CPTScatterPlot *)plot recordIndex:(NSUInteger)index
{
CPTPlotSymbol *symbol = [[CPTPlotSymbol alloc]init];
if (index %2 == 0)
{
symbol.symbolType = CPTPlotSymbolTypeDiamond;
symbol.fill = [CPTFill fillWithColor:[CPTColor redColor]];
symbol.size = CGSizeMake(10, 10);
return symbol;
}
else
{
symbol.symbolType = CPTPlotSymbolTypeEllipse;
symbol.fill = [CPTFill fillWithColor:[CPTColor orangeColor]];
symbol.size = CGSizeMake(15, 15);
return symbol;
}
}
并且当我 select 我的 scatter plot
中的任何绘图符号时,我想将那个 selected 绘图符号转换为 UIImage
,因为在转换成图像后我想要将图像从源位置拖到任何其他地方plotspace
。
我实现了委托方法从我的散点图中获取 selected 绘图符号,代码是
- (void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
CPTPlotSymbol *selectedSymbol = [plot plotSymbolForRecordIndex:index];
NSLog(@"%@", selectedSymbol);
}
从上面的代码中,我得到了我的 selected 绘图符号对象。但从这里我不知道如何将这个绘图符号对象转换为 UIImage
。如果有人指导我,那就太好了,或者有任何其他更好的方法来解决我的问题意味着也请以这种方式帮助我。提前致谢
您可以使用-renderAsVectorInContext:atPoint:scale:
方法将符号绘制成CGContext
。创建上下文,将符号绘制到其中,并使用UIGraphicsGetImageFromCurrentImageContext()
创建一个UIImage
。