GPUImage 2在collectionview中过滤

时间:2016-12-25 14:01:46

标签: ios swift image-processing gpuimage

我正在iOS中使用swift GPUImage2 Library制作图像编辑应用程序。在这里,我将实现一些过滤器,这些过滤器将在传统图像编辑应用程序的uicollectionview中进行预览。

我为collectionview生成了50x50的拇指图像,然后对其应用了过滤器。我的过滤代码是:

var filterOptions = [FilterOption]();
var thumbInput: PictureInput!;
    let meFilter = MissEtikateFilter()
    let sketchFilter = SketchFilter();
    let softeleganceFliter = SoftElegance()

    var pictureOutput = PictureOutput()

    func thumbFilters() {

        pictureOutput.imageAvailableCallback = {image in
            // Do something with image
            self.filterOptions.append(FilterOption(name: "MissEtikateFilter", image: image))

        }
        thumbInput --> meFilter --> pictureOutput
        thumbInput.processImage(synchronously: true)


        sketchFilter.edgeStrength = 1;
        pictureOutput.imageAvailableCallback = {image in
            // Do something with image
            self.filterOptions.append(FilterOption(name: "SketchFilter", image: image))

        }
        thumbInput --> sketchFilter --> pictureOutput
        thumbInput.processImage(synchronously: true)


        pictureOutput.imageAvailableCallback = {image in
            // Do something with image
            self.filterOptions.append(FilterOption(name: "SoftElegance", image: image))

        }
        thumbInput --> softeleganceFliter --> pictureOutput
        thumbInput.processImage(synchronously: true)
    }

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {            
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FilterCell", for: indexPath as IndexPath) as! FilterCell
            cell.OptionIcon.image = filterOptions[indexPath.item].image;
            return cell;

    }

我在这里做的是我正在制作过滤的UIImage并将它们添加到collectionview数据数组中,然后重新加载它。我不确定这是不是一个好主意。但问题是我只将第一个过滤器应用于所有这些过滤器。

Output i m getting

当我在应用每个滤镜之前初始化pictureOutput时,我会得到红色图像......打开视图控制器时它甚至不平滑。

output

所以我想我可能会以错误的方式做这件事。我没有在collectionview中找到任何处理这个的好资源。如果有人能给我看一个git项目或教程或其他东西会更好。也赞赏任何建议

由于

1 个答案:

答案 0 :(得分:0)

尝试为每行创建不同的单元格,因为.. 我认为问题出在reuseIdentifier ..它重用了imageView ..并重叠它们..尝试创建没有reuseIdentifier的单元格。

实施例。

cell = let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "FilterCell")

OR

尝试为这3个imageViews创建不同的对象,而不是使用1.

喜欢

func thumbFilters() {

        var pictureOutput = PictureOutput()

        pictureOutput.imageAvailableCallback = {image in
            // Do something with image
            self.filterOptions.append(FilterOption(name: "MissEtikateFilter", image: image))

        }
        thumbInput --> meFilter --> pictureOutput
        thumbInput.processImage(synchronously: true)

        // create again
        pictureOutput = PictureOutput()

        sketchFilter.edgeStrength = 1;
        pictureOutput.imageAvailableCallback = {image in
            // Do something with image
            self.filterOptions.append(FilterOption(name: "SketchFilter", image: image))

        }

        // create again
        pictureOutput = PictureOutput()

        thumbInput --> sketchFilter --> pictureOutput
        thumbInput.processImage(synchronously: true)


        pictureOutput.imageAvailableCallback = {image in
            // Do something with image
            self.filterOptions.append(FilterOption(name: "SoftElegance", image: image))

        }
        thumbInput --> softeleganceFliter --> pictureOutput
        thumbInput.processImage(synchronously: true)
    }