-1
目前我正在开发基于相机的应用程序。我使用UIImageView内的相机图像来更容易操作。现在我想从核心成像添加一些效果。我能以某种方式从视图中获得图像吗?从UIImageView获取UIImage
这是我如何添加效果,但它只适用于图像。
NSString *filePath =
[[NSBundle mainBundle] pathForResource:@"IpadIcon" ofType:@"png"];
NSURL *fileNameAndPath = [NSURL fileURLWithPath:filePath];
CIImage *beginImage =
[CIImage imageWithContentsOfURL:fileNameAndPath];
CIContext *context = [CIContext contextWithOptions:nil];
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone" keysAndValues: kCIInputImageKey, beginImage, @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg =
[context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg];
[captureImage setImage:newImg];
获取图像
- (void) capImage { //method to capture image from AVCaptureSession video feed
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
videoConnection = connection;
break;
}
}
if (videoConnection) {
break;
}
}
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
if (imageSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
[self processImage:[UIImage imageWithData:imageData]];
}
}];
}
你能具体谈谈您遇到的问题? –
我有一个UIImageView内的图片。现在我需要把它弄出来。可能吗 ? – WildWorld
'UIImage * theImage = imageView.image;'? – hgwhittle