1

このコードのように画像をマスクしたい:

CGFloat plx = inputImage.size.width/_imageView.frame.size.width;
CGFloat ply = inputImage.size.height/_imageView.frame.size.height;

CGFloat radius = MIN(_postionView.frame.size.width * plx, _postionView.frame.size.height * ply)/1.5;

CIVector *cen = [CIVector vectorWithX:_postionView.center.x * plx Y:_postionView.center.y * ply];

CIFilter *radialGradient = [CIFilter filterWithName:@"CIRadialGradient" keysAndValues:
                            @"inputRadius0", [NSNumber numberWithFloat:radius],
                            @"inputRadius1", [NSNumber numberWithFloat:radius + 1.0f],
                            @"inputColor0", [CIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0],
                            @"inputColor1", [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],
                            @"inputCenter", cen,
                            nil];

CIImage *circleImage = [radialGradient valueForKey:kCIOutputImageKey];

_postionViewは私のuiimageviewです。正しい位置になりません。これは、uikit座標系とクォーツ座標系が異なるためだと思います。何か案は?

4

1 に答える 1

0

解決済みです。以下はコードを解決する方法です:</p>

CGPoint touchPoint = [touch locationInView:self.view];
ScaleX = _imageView.image.size.width/self.view.frame.size.width;
ScaleY = _imageView.image.size.height/self.view.frame.size.height;

CGFloat imgX;
CGFloat imgY;

imgX = touchPoint.x * ScaleX;
imgY = _imageView.image.size.height - touchPoint.y * ScaleY;

VICPoint = CGPointMake(imgX, imgY);

CIImage *maskImage = nil;
CIVector *cen;

cen = [CIVector vectorWithX:VICPoint.x Y:VICPoint.y];
CGFloat radius = MIN(80 * ScaleX, 80 * ScaleY)/1.5;

CIFilter *radialGradient = [CIFilter filterWithName:@"CIRadialGradient" keysAndValues:
                            @"inputRadius0", [NSNumber numberWithFloat:radius],
                            @"inputRadius1", [NSNumber numberWithFloat:radius + 1.0f],
                            @"inputColor0", [CIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0],
                            @"inputColor1", [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],
                            @"inputCenter", cen,
                            nil];

CIImage *circleImage = [radialGradient valueForKey:kCIOutputImageKey];
于 2012-11-10T07:22:50.147 に答える