1
아래 그림과 같이 어떻게 이미지를 그릴 수 있습니까? 사진 편집 도구에서이 사진을 만들었습니다. 하지만 iOS를 사용하여 실제로 그걸 풀 수는 없습니다.타원 그라디언트 그리기
- 타원은
- "소프트 코너 '방식으로 그것은 원형이 아니다 것만 빛나는 그라데이션 같다.
코드 :
이+(UIImage*)createGradientOval2:(const CGSize)SIZECONTEXT {
const CGFloat SCALE = 2.0f;
UIGraphicsBeginImageContextWithOptions(SIZECONTEXT, NO, SCALE);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Create gradient
CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
const CGFloat colors [] = {
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 1.00, // green
0.0, 1.0, 0.0, 0.00, // transparent
};
//CGGradientRef gradient = CGGradientCreateWithColors(baseSpace, (CFArrayRef)colors, locations);
CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 10);
CGColorSpaceRelease(baseSpace), baseSpace = NULL;
// Scaling transformation and keeping track of the inverse
CGAffineTransform scaleT = CGAffineTransformMakeScale(1, 2.0);
CGAffineTransform invScaleT = CGAffineTransformInvert(scaleT);
// Extract the Sx and Sy elements from the inverse matrix
// (See the Quartz documentation for the math behind the matrices)
CGPoint invS = CGPointMake(invScaleT.a, invScaleT.d);
const CGRect RECT = CGRectMake(0, 0, SIZECONTEXT.width/2, SIZECONTEXT.height/2);
// Transform center and radius of gradient with the inverse
CGPoint center = CGPointMake((RECT.size.width/2) * invS.x, (RECT.size.height/2) * invS.y);
CGFloat radius = (RECT.size.width/2) * invS.x;
// Draw the gradient with the scale transform on the context
CGContextScaleCTM(ctx, scaleT.a, scaleT.d);
CGContextDrawRadialGradient(ctx, gradient, center, 0, center, radius, kCGGradientDrawsBeforeStartLocation);
// Reset the context
CGContextScaleCTM(ctx, invS.x, invS.y);
// Continue to draw whatever else ...
// Clean up the memory used by Quartz
CGGradientRelease(gradient);
return UIGraphicsGetImageFromCurrentImageContext();
}
이 방법이 가장 효율적인 방법은 아닌지 잘 모르겠지만 이러한 것들이 많이 필요하지 않으면 확실히 빠릅니다. 나에게 아주 편리하게 왔어. 포인터 주셔서 감사! – DanM