UIBezierPath到UIImage

UIBezierPath到UIImage

本文介绍了UIBezierPath到UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我需要绘制一个饼图。我在这里找到了一个不错的教程

I need to draw a pie chart. I found a nice tutorial here http://mac-objective-c.blogspot.com/2009/04/drawing-pie-charts.html

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

The example uses NSBezierPath, but I use UIBezierPath because I need the graphic in IOS.

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

Is there a way to obtain that graphic in a UIImage so I can show it in a UIImageView?

在本教程他们使用CGContext,最后他们有一个函数返回a UIImage。

In this tutorial http://blog.gafmediastudio.com/2010/07/02/draw-a-pie-chart-with-iphone-ipod-ipad/ they use CGContext and in the end they have a function that returns a UIImage.

UIBezierPath类似乎更容易使用,那么如何在UIImage中绘制图形?从我已经读的altering drawRect不是非常推荐。

The UIBezierPath Class seems easier to use, so how could I get that drawing in a UIImage? From what I have read altering drawRect is not very recommended. At least, not for what I am trying to do.

谢谢!

推荐答案

首先拍摄您的屏幕图片并裁剪所需大小的图片。

First take a picture of your screen and crop the image of your desired size.

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];

这篇关于UIBezierPath到UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:36