GPUImage
GPUImage copied to clipboard
image blur when use GPUImageUIElement
I current use GPUImageUIElement to add watermark.But compare with the original image ,the image is a litter blur in the camera.Can anyone help me.Thanks very much! Code is below.
GPUImageFilter *filter = [[GPUImageFilter alloc] init]; [self.videoCamera addTarget:filter];
_blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
_blendFilter.mix = 1.0;
NSDate *startTime = [NSDate date];
_dynamicImgView = [[UIImageView alloc] initWithFrame:CGRectMake(30, SCREEN_HEIGHT - 210, SCREEN_WIDTH - 60, 50)];
_dynamicImgView.center = CGPointMake(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0);
_dynamicImgView.image = [UIImage imageNamed:@"icon_record_dynamic_0"];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
[view addSubview:_dynamicImgView];
_imgArray = @[@"icon_record_dynamic_0",@"icon_record_dynamic_1",@"icon_record_dynamic_2",@"icon_record_dynamic_3"];
uiElementInput = [[GPUImageUIElement alloc] initWithView:view];
[filter addTarget:_blendFilter];
[uiElementInput addTarget:_blendFilter];
[_blendFilter addTarget:_previewView];
WeakSelf;
__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;
[filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
@autoreleasepool {
NSInteger index = -[startTime timeIntervalSinceNow];
NSInteger count = weakSelf.imgArray.count;
NSString *imgName = weakSelf.imgArray[index % count];
UIImage *image = [UIImage imageNamed:imgName];
weakSelf.dynamicImgView.image = image;
weakSelf.dynamicImgView.height = (image.size.height / image.size.width) * (SCREEN_WIDTH - 60);
weakSelf.dynamicImgView.top = SCREEN_HEIGHT - 160 - weakSelf.dynamicImgView.height;
}
[weakUIElementInput update];
}];
[_blendFilter addTarget:self.movieWriter];
[self.videoCamera startCameraCapture];
Did you have the solution?I have the same question.
Any luck?
That's because GPUImageUIElement is using layer.contentsScale to calculate the size in pixels.
- (CGSize)layerSizeInPixels;
{
CGSize pointSize = layer.bounds.size;
return CGSizeMake(layer.contentsScale * pointSize.width, layer.contentsScale * pointSize.height);
}
so just modify your view.layer.contentsScale
view.layer.contentsScale = [UIScreen mainScreen].scale;