本文介绍了如何从GPUImageView获取UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用GPUImageView库,它正在使用GPUImageView,我在GPUImageView上添加了像对比度和其他图像效果(如棕褐色等)的过滤器,一切都很好,但问题是现在我想将GPUImageVIew转换为UIImage所以我可以从UIImage中提取图像并在Facebook上发布该图像,但我无法做到这一点,在Facebook上发布的图像是简单的相机捕获图像,没有使用GPUIMageView添加的特殊效果。如何实现这一目标。请帮帮我。谢谢提前...以下是我的代码

I am using GPUImageView library in my project where it is using GPUImageView and i have added filters like contrast and other image effects like sepia etc on that GPUImageView , everything is good but problem is now i want to convert that GPUImageVIew into UIImage so that i can extract the image out of that UIImage and post that image on Facebook , but i am not able to do that the image which is getting post on facebook is simple camera captured image without special effects which i added using GPUIMageView . How to achieve this . Please help me .Thanks in Advance ... Below is my code

    -(void) loadFilters
{
    for(int i = 0; i < 10; i++)
    {
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i + 1]] forState:UIControlStateNormal];
        button.frame = CGRectMake(10+i*(60+10), 5.0f, 60.0f, 60.0f);
        button.layer.cornerRadius = 7.0f;

        //use bezier path instead of maskToBounds on button.layer
        UIBezierPath *bi = [UIBezierPath bezierPathWithRoundedRect:button.bounds
                                                 byRoundingCorners:UIRectCornerAllCorners
                                                       cornerRadii:CGSizeMake(7.0,7.0)];

        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.frame = button.bounds;
        maskLayer.path = bi.CGPath;
        button.layer.mask = maskLayer;

        button.layer.borderWidth = 1;
        button.layer.borderColor = [[UIColor blackColor] CGColor];

        [button addTarget:self
                   action:@selector(filterClicked:)
         forControlEvents:UIControlEventTouchUpInside];
        button.tag = i;
       // [button setTitle:@"*" forState:UIControlStateSelected];
        if(i == 0){
            [button setSelected:YES];
        }
        [self.filterScrollView addSubview:button];
    }
    [self.filterScrollView setContentSize:CGSizeMake(10 + 10*(60+10), 75.0)];
}
-(void) filterClicked:(UIButton *) sender
{
    for(UIView *view in self.filterScrollView.subviews)
    {
        if([view isKindOfClass:[UIButton class]])
        {
            [(UIButton *)view setSelected:NO];
        }
    }

    [sender setSelected:YES];
    [self removeAllTargets];

    selectedFilter = sender.tag;
    [self setFilter:sender.tag];
    [self prepareFilter];
}

-(void) setFilter:(int) index
{
    UIImage *inputImage = [UIImage imageNamed:@"[email protected]"];
    img_New = [[UIImage alloc] init];
    switch (index) {
        case 1:
        {
            filter = [[GPUImageContrastFilter alloc] init];
            [(GPUImageContrastFilter *) filter setContrast:1.75];
           // img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew1.png"]];
            }
        } break;
        case 2:
        {
            filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"crossprocess"];
            //img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew2.png"]];
            }
        } break;
        case 3:
        {
            filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"02"];
            //img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew3.png"]];
            }
        } break;
        case 4:
        {
            filter = [[GrayscaleContrastFilter alloc] init];
            //img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew4.png"]];
            }
        } break;
        case 5:
        {
            filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"17"];
            //img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew5.png"]];
            }
        } break;
        case 6: {
            filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"aqua"];
            //img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew6.png"]];
            }
        } break;
        case 7: {
            filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"yellow-red"];
            //img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew7.png"]];
            }
        } break;
        case 8: {
            filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"06"];
           // img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew8.png"]];
            }
        } break;
        case 9: {
            filter = [[GPUImageToneCurveFilter alloc] initWithACV:@"purple-green"];
           // img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@"borderNew9.png"]];
            }
        } break;
        default:
            filter = [[GPUImageFilter alloc] init];
            //img_New = [filter imageByFilteringImage:inputImage];
            if(Border==NO)
            {
                [imgBorder setImage:[UIImage imageNamed:@""]];
            }
            break;
    }
}


推荐答案

你可以通过

UIImage *currentFilteredImage = [filter imageFromCurrentlyProcessedOutput];

这篇关于如何从GPUImageView获取UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 06:54