내 이미지에서 구멍을 자르는 방법은 있습니까? 내가 원하는 건 눈과 입을 자르는 것입니다. 투명하게되기를 바랍니다.ios - UIImage에서 구멍을 자르는 방법
0
A
답변
6
UIBezierPath를 닫힌 패스의 모든 정점이 투명하게 만들도록 만듭니다. 베 지어 경로는 다음과 같이 구성되어 있습니다
UIBezierPath *currentPath = [UIBezierPath bezierPath];
CGPoint tempPoint = CGPointMake(0,0);
[currentPath moveToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
tempPoint = CGPointMake(0,20);
[currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
tempPoint = CGPointMake(20,20);
[currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
tempPoint = CGPointMake(20,0);
[currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
[currentPath closePath];
을하고 그 영역을 투명하게하고 새로운 이미지로 저장하려면 다음 코드를 사용
// Create an image context containing the original UIImage.
UIGraphicsBeginImageContext(originalImage.size);
[originalImage drawAtPoint:CGPointZero];
// Clip to the bezier path and clear that portion of the image.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context,currentPath.CGPath)
CGContextClip(context);
CGContextClearRect(context,CGRectMake(0,0,originalImage.size.width,originalImage.size.height);
// Build a new UIImage from the image context.
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
+0
감사를 절단 할 필요가 터치 영역을 필요로 할 어떤 경로를 정의 할 수 있습니다. 그것은 나를 많이 돕는다. – user2951348
1
이 하나
먼저 quartzcore를 추가하십시오
#import <QuartzCore/QuartzCore.h>
클립 할 경로 만들기
,UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:yourView.bounds];
[maskPath appendPath:[UIBezierPath bezierPathWithRect:rectToPunchThroughTheView]];
그리고 마스크 레이어를 생성하고보기에 추가 - CAShapeLayer는
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.fillRule = kCAFillRuleEvenOdd;
maskLayer.fillColor = [UIColor blackColor].CGColor;
maskLayer.path = maskPath.CGPath;
yourView.layer.mask = maskLayer;
관련 문제
- 1. UIImage에서 구멍을 자르는 방법?
- 2. UIImage에서 중심 사각형을 자르는 방법?
- 3. IOS : UIImage에서 알파 설정
- 4. iOS UIImage에서 null을 반환합니다.
- 5. iOS, UIImage에서 획이있는 텍스트 그리기
- 6. Core Graphics - UIImage에서 불투명 한 픽셀을 자르는 법?
- 7. UIImage에서 tapgesture를 감지하는 방법?
- 8. OpenGL에서 벽에 구멍을 만드는 방법
- 9. 큐브 개체에서 구멍을 파는 방법?
- 10. WhirlyGlobe의 극 구멍을 패치하는 방법
- 11. iOS : UIImage에서 NSString 및 테두리 그리기
- 12. iOS UIImage에서 JPEG 이미지를 표시하지 않습니다.
- 13. iOS - UIImage에서 EXIF UserComment 가져 오기
- 14. UIImage에서 CGPath 만들기
- 15. URL을 UIImage에서 가져 오는 방법
- 16. UIImage에서 투명한 영역을 얻는 방법?
- 17. SKNode에 구멍을 내고 PhysicsBody를 Swift에서 업데이트하십시오.
- 18. UIImage에서 BitmapContext로
- 19. UIImage에서 그리기
- 20. three.js의 평면에 투명한 구멍을 만드는 방법
- 21. 이 콘솔 회전 애니메이션의 구멍을 수정하는 방법
- 22. SWIFT : UIImage에서 UILabel 그리기
- 23. 문에 구멍을 뚫었나요?
- 24. 티파니에서 직사각형을 자르는 방법?
- 25. 양면에서 6 % 자르는 방법?
- 26. 공백없이 문자열을 자르는 방법
- 27. .net에서 날짜를 자르는 방법?
- 28. RichTexBox 텍스트를 자르는 방법
- 29. HWND 제목을 자르는 방법
- 30. 이미지를 프레임으로 자르는 방법
는 u는 대답/투명 – Spynet