zoukankan      html  css  js  c++  java
  • xcode配置openGL

    git clone https://github.com/BradLarson/GPUImage

    先git clone 下这个库:

    可以看到拉下来的代码里有一些examples:选择Mac文件夹里的SimplePhotoFilter文件夹里的SimplePhotoFilter.xcodeproj

     打开工程之后,把 GPUImageMac.xcodeproj 文件拖到 Frameworks下面。

     再点击工程里的TARGETS -> Build Phases -> Dependencies -> 添加GPUImage

     添加 TARGETS -> Build Phases -> Link Binary With Libraies -> (点击+号) 添加GPUImage.framework 和 Cocoa.framework

     在SLSDocument.m文件中写主要步骤,自己再定义一个filter文件来重写想要实现的滤镜逻辑。

    - (void)windowControllerDidLoadNib:(NSWindowController *)aController
    {
        [super windowControllerDidLoadNib:aController];
        // Add any code here that needs to be executed once the windowController has loaded the document's window.
        
        NSLog(@"Did load nib");
        
    //    [inputPicture addTarget:imageFilter];
    //    [imageFilter addTarget:self.imageView];
        
    //    [inputPicture addTarget:self.imageView];
    //    [inputPicture processImage];
        
        NSImage *sourceImage = [[NSImage alloc] initWithContentsOfFile:@"/Users/bella/Desktop/单步数据/IMG_0154.JPG"];
        //获取数据源
        inputPicture = [[GPUImagePicture alloc] initWithImage:sourceImage];
        //创建黑白素描滤镜
        TempFilter *sobelFilter = [[TempFilter alloc] init];
    //    GPUImageBrightnessFilter *sketchFilter = [[GPUImageBrightnessFilter alloc] init];
    //    sketchFilter.brightness = 0.5;
        
        //设置要渲染的区域
        [sobelFilter setupFilterForSize:sourceImage.size];
        
        
        [inputPicture addTarget:sobelFilter];
        GPUImageFilter *lasterFilter = sobelFilter;
    //    [imageFilter addTarget:sketchFilter];
        
        [lasterFilter addTarget:self.imageView];
        [lasterFilter useNextFrameForImageCapture];
        
        //开始渲染
        [inputPicture processImage];
        //获取渲染后的图片
        NSImage *resultImage = [lasterFilter imageFromCurrentFramebuffer];
        NSData *imageData = [resultImage TIFFRepresentation];
        NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
        NSDictionary *imageProps = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];
        imageData = [imageRep representationUsingType:NSJPEGFileType properties:imageProps];
        BOOL writeResult = [imageData writeToFile:@"/Users/bella/Desktop/单步数据/output.JPG" atomically:NO];
        NSLog(@"Write result %@", @(writeResult));
        NSLog(@"");
        
        return;
    }
  • 相关阅读:
    如何输出高精度时间差
    GetThreadTimes获取其它线程cpu时间
    12-Python基础之类与面向对象
    10-Python函数之递归
    09-Python基础之内置函数与匿名函数
    08-Python基础之迭代器与生成器
    07-Python基础之装饰器
    06-Python基础之函数进阶(嵌套,作用域)
    05-Python基础之函数基础
    04-Python基础之文件操作基础
  • 原文地址:https://www.cnblogs.com/Bella2017/p/13025150.html
Copyright © 2011-2022 走看看