I'm having troubles cropping image. For me CICrop filter is not working properly. If my CIVector x and y (origins) are 0 everything working fine (image is cropped from left bottom corner), image is cropped by my rectangle width and height, but if CIVector origins (x and y) aren't 0 in my cropped image becomes space (because CICrop filter cropping from bottom left corner no matter what origins (x and y) are).
I'm cropping CIImage with rectangle, source:
CIVector *cropRect =[CIVector vectorWithX:150 Y:150 Z: 300 W: 300];
CIFilter *cropFilter = [CIFilter filterWithName:@"CICrop"];
[cropFilter setValue:myCIImage forKey:@"inputImage"];
[cropFilter setValue:cropRect forKey:@"inputRectangle"];
CIImage *croppedImage = [cropFilter valueForKey:@"outputImage"];
Output Image with CIVector X 150 and Y 150: (I drawn the border for clarity)
Output Image with CIVector X 0 and Y 0:
Original Image:
What I'm doing wrong? Or is it supposed to do this?
It's important to note that the coordinate system of a view is top-left-corner, whereas CIImage is bottom left. This will make you crazy if you don't catch it when you're doing these transforms! This other post describes a one-directional conversion: Changing CGrect value to user coordinate system.
Are you sure the output image is the size you are expecting? How are you drawing the output image?
The
CICrop
filter does not reduce the size of the original image, it just blanks out the content you don't want.To get the result you want you probably need to just do this:
If you want an actual
CIImage
as output rather than just drawing it, just do this: