2013-06-26 44 views
0

什麼是最簡單和性能最低的方法來實現這一目標?如何在iOS中的圖像上繪製UIBezierPath?

現在我有一個超過60000行的UIBezier路徑。我想從中創建一個圖像,稍後將在屏幕上移動並拉伸。

+0

看到這個問題第一個答案:http://stackoverflow.com/questions/11739816/ios-uiimage-image-upside-down但不是在上下文中繪製一個UIImage,在上下文 – V1ru8

+0

繪製你的路徑,但如何我是否可以繪製該圖像? CGContextDrawPath?或者我應該只使用[path stroke]並將其繪製到圖像上? – HSNN

+0

http://stackoverflow.com/questions/17408209/how-to-create-a-image-with-uibezierpath/40908425#40908425 – Shrawan

回答

9

只需創建一個圖形上下文,並繪製路徑進去,就像這樣:

UIGraphicsBeginImageContextWithOptions(path.bounds.size, NO, 0.0); //size of the image, opaque, and scale (set to screen default with 0) 
[path fill]; //or [path stroke] 
UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

如果你在走動的形象策劃,你就需要把它拉進你的看法,或最好一個UIImageView,它是該視圖的子視圖。這比每次用戶移動手指時重新繪製視圖都快。

希望這會有所幫助!

+0

第一線對的Xcode警告:'的功能隱式聲明「UIGraphicsCreateImageContextWithOptions」是無效的'和建築失敗:'對於架構i386的未定義符號: 「_UIGraphicsCreateImageContextWithOptions」' – HSNN

相關問題