简体   繁体   中英

How to create UIImage from CPTPlotSymbol?

I am new to Core-Plot , and here is my problem.

I created my Graph using ScatterPlot class. And my plot symbol creation data source method is:

- (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;
    }
}

And when i select any plot symbol from my scatter plot , i want to convert that selected plot symbol to UIImage , because after converting into image i want to drag the image from the source place to any other place with that plotspace .

I implemented delegate method to get the selected plot symbol from my scatter plot, the code is

- (void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{
    CPTPlotSymbol *selectedSymbol = [plot plotSymbolForRecordIndex:index];
    NSLog(@"%@", selectedSymbol);
}

from above code i am getting my selected plot symbol object. but from here i don't know how to covert this plot symbol object to UIImage . if any one guide me it will be great or there is any other better way to solve my problem means kindly help me in that way also. Thanks in advance

You can use the -renderAsVectorInContext:atPoint:scale: method to draw the symbol into a CGContext . Create a context, draw the symbol into it, and use UIGraphicsGetImageFromCurrentImageContext() to create a UIImage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM