问题
I am just about done with my App and have added some great things with core plot and the help of their dedicated staff. My question pertains to using images with the retina display. I have an annotation that is a picture of a speech bubble. When I run the App in the simulator, it displays fine for regular resolution, but when I switch to retina, the image is cropped. See pictures below. I have a .png that I called Bubble, and I added another that is called Bubble@2x, which is twice the size, I thought this was what I needed to do. That did not work. So I have tried to set the view.contentScale, see below code. But nothing seems to work. Anyone have any ideas what I am forgetting to do? Thanks once again.
{
//first annotation
NSValue *value = [self.myData objectAtIndex:index];
CGPoint point = [value CGPointValue];
NSString *number1 = [NSString stringWithFormat:@"(%.2f, ", point.x];
NSString *number2 = [NSString stringWithFormat:@"%.2f)", point.y];
NSNumber *x = [NSNumber numberWithFloat:point.x];
NSNumber *y = [NSNumber numberWithFloat:point.y];
NSArray *anchorPoint = [NSArray arrayWithObjects: x, y, nil];
NSString *final = [number1 stringByAppendingString:number2];
//second annotation
UIImage *bubble = [UIImage imageNamed:@"Bubble.png"];
CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage];
CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] init];
//imageLayer.contentsScale = [[UIScreen mainScreen] scale]; //tried this
imageLayer.frame = CGRectMake(0, 0, 150, 80);
//imageLayer.contentsScale = 2.0f; //and this
imageLayer.fill = [CPTFill fillWithImage:fillimage];
CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:final style:annotationTextStyle];
_annotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
_annotation.contentLayer = textLayer;
_annotation.displacement = CGPointMake(90.0f, 5.0f);
_annotation.rotation = M_PI * .03f;
_picAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
_picAnnotation.contentLayer = imageLayer;
_picAnnotation.displacement = CGPointMake(75.0f, 5.0f);
}
after that code, I then placed both of the annotations. As you can see one works, the other doesn't.
回答1:
You should pass the image scale
when creating a CPTImage
if you need to support Retina images.
CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage
scale:bubble.scale];
来源:https://stackoverflow.com/questions/12494324/core-plot-1-0-retina-images-not-displayed-correctly