2016-01-21 46 views
-3

請help.I有兩個圖像視圖 - 一個黑色和一個紅色。我通過兩條線繪製線條,並且在去除深色圖像視圖後,深綠線應保持紅色(裁剪)並保存到最終圖像。通過兩個圖像畫線

enter image description here

+0

你可以提供一些代碼或更多關於你正在使用的信息?你使用UIViews,UIImages? – TastyCat

+0

檢查此http://stackoverflow.com/questions/13008419/how-to-draw-line-on-the-uiimageview-not-for-uiview –

+0

謝謝。這是一個例子,如何在一幅圖像上繪製線條,但我需要在兩個或修復問題的波紋管。紅色圖像視圖在中間有一個清晰的顏色(UIImage有300x500,圖像有150x200和scaletofit)。當我畫一條線時,線條也是清晰的背景,看起來很糟糕。我只需要畫一些東西的部分。 – ankmara

回答

0

考慮到你已經使用了三個圖像視圖。

IBOutlet UIImageView *lineView; 
IBOutlet UIImageView *blackView; 
IBOutlet UIImageView *redView; 

您需要使用下面的代碼來獲得精確的裁剪圖像爲每redView框架。

UIGraphicsBeginImageContext(redView.frame.size); 

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGRect frame = lineView.frame; 
frame.origin.x = lineView.frame.origin.x - redView.frame.origin.x ; 
frame.origin.y = lineView.frame.origin.y - redView.frame.origin.y; 

[redView.image drawInRect:redView.bounds]; 
[lineView.image drawInRect:frame]; 

CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor); 
UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
redView.image = img; 
UIGraphicsEndImageContext(); 
+0

非常感謝 – ankmara