2012-04-06 2 views
0

...아이폰 OS : 역 UIBezierPath (bezierPathWithOvalInRect) 나는 RECT에 둥근 객체에 JPG 이미지를 투명 라운드 개체의 envoirement을 만들고 싶어

Example

(빨간색 영역을 제거 이 예제)

iOS make part of an UIImage transparent과 "UIBezierPath bezierPathWithOvalInRect"의 도움으로 약간의 성공을 거두었지만 내 물건을 둘러싼 경로를 만들어 내고, 그것을 뒤집어서 내부와 외부를 만들어야합니다. 경로의 투명 ..

내가 올바른 결과를 얻을하려면 코드를 변경해야 할 경우 임 슈어하지 16,

.. 여기

내 코드입니다 :

//BezierPath 
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)]; 

// Create an image context containing the original UIImage. 
UIGraphicsBeginImageContext(_imgTemp.image.size); 
[_imgTemp.image drawAtPoint:CGPointZero]; 

// Clip to the bezier path and clear that portion of the image. 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextAddPath(context,bezierPath.CGPath); 
CGContextClip(context); 
CGContextClearRect(context,CGRectMake(0,0,self._imgTemp.image.size.width,self._imgTemp.image.size.height)); 

// Build a new UIImage from the image context. 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
self._imgTemp.image = newImage; 

누구는 해결되었다?

+0

은 검은 색이 투명하게 만 적색 투명하게 만들고 싶어 마십시오? –

답변

9

은 당신이 CGContextClip(context); 이후에 [_imgTemp.image drawAtPoint:CGPointZero];를 이동 한 후 완전히 CGContextClearRect(...) 호출을 제거해야합니다 검은 색 원 안에 그리려면

//BezierPath 
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)]; 

// Create an image context containing the original UIImage. 
UIGraphicsBeginImageContext(_imgTemp.image.size); 

// Clip to the bezier path and clear that portion of the image. 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextAddPath(context,bezierPath.CGPath); 
CGContextClip(context); 

// Draw here when the context is clipped 
[_imgTemp.image drawAtPoint:CGPointZero]; 

// Build a new UIImage from the image context. 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
self._imgTemp.image = newImage; 
+0

안녕하세요. 완전히 작동합니다. 빠른 답변에 감사드립니다. – Jones123

+0

'[bezierPath addClip]'을 사용하여 현재 컨텍스트를 UIBezierPath로 클립 할 수 있으므로'CGContextRef'를 직접 들여다 쓸 필요가 없습니다. – Dondragmer

+0

완벽 ;) 감사 –

관련 문제