0

我需要画一个饼图。我在这里找到了一个不错的教程http://mac-objective-c.blogspot.com/2009/04/drawing-pie-charts.html

该示例使用 NSBezierPath,但我使用 UIBezierPath 因为我需要 IOS 中的图形。

有没有办法在 UIImage 中获取该图形,以便我可以在 UIImageView 中显示它?

在本教程http://blog.gafmediastudio.com/2010/07/02/draw-a-pie-chart-with-iphone-ipod-ipad/他们使用 CGContext 并且最后他们有一个返回 UIImage 的函数.

UIBezierPath 类似乎更易于使用,那么我如何才能在 UIImage 中获得该绘图?从我读过的内容来看,不太推荐改变 drawRect 。至少,不是因为我想做的事。

谢谢!

4

1 回答 1

3

首先为您的屏幕拍照并裁剪所需尺寸的图像。

UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//Crop the image
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake(0, 44, 1024, 660));
img = [UIImage imageWithCGImage:imageRef];
于 2012-04-25T05:25:30.973 回答