BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.22k stars 4.62k forks source link

image blur when use GPUImageUIElement #2480

Open angBiu opened 7 years ago

angBiu commented 7 years ago

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];
IphoneCoder commented 6 years ago

Did you have the solution?I have the same question.

LuoyeAn commented 5 years ago

Any luck?

hezhk3 commented 5 years ago

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;