objective-c 我的美图软件


//  ViewController.m

//  我的美图软件

//

//  Created by DC017 on 16/1/5.

//  Copyright © 2016 DC017. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>

{   //相册视图控制器

    UIImagePickerController * imagePickerController;

    UIImage * image;

    //是滤镜里面的

    CIImage * zhiqianimage;//编辑之前

    //是滤镜里面的

    CIImage * zhihouimage;//编辑之后

    //滤镜

    CIFilter * filter;

    //上下文

    CIContext * context;

}

@end


@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    //相册视图控制器

    imagePickerController=[[UIImagePickerController alloc]init];

    imagePickerController.delegate=self;

    //自适应图片大小

    _imageView.contentMode=UIViewContentModeScaleAspectFit;

    //初始化滤镜

    filter=[CIFilter filterWithName:@"CIColorControls"];

    //初始化上下文

    context=[CIContext contextWithOptions:nil];

}


//协议里的方法

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

    //关闭相册(从那来回那我去)

    [self dismissViewControllerAnimated:YES completion:nil];

    //获取选择的图片

    image=[info objectForKey:UIImagePickerControllerOriginalImage];

    _imageView.image=image;

    //初始化CI

    zhiqianimage=[CIImage imageWithCGImage:[image CGImage]];

    [filter setValue:zhiqianimage forKey:@"inputImage"];

}

//打开相册

- (IBAction)daikaixiangce:(id)sender {

    //模态跳转(针对视图控制器)

    [self presentViewController:imagePickerController animated:YES completion:nil];

}


- (IBAction)baocunzhaopain:(id)sender {

    //保存到相册

    UIImageWriteToSavedPhotosAlbum(_imageView.image, nil, nil, nil);

    //实例化弹出框

    UIAlertController * tanChuKuang=[UIAlertController alertControllerWithTitle:@"信息" message:@"保存成功" preferredStyle:UIAlertControllerStyleAlert];

    //设置弹出框属性

    [tanChuKuang addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:nil]];

    //模态跳转到弹出框

    [self presentViewController:tanChuKuang animated:YES completion:nil];

}

//CI->CG->UI

-(void)setimage{

    //取出输出图片

    zhihouimage=[filter outputImage];

    CGImageRef temp=[context createCGImage:zhihouimage fromRect:[zhiqianimage extent]];

    _imageView.image=[UIImage imageWithCGImage:temp];

    CGImageRelease(temp);

}

//调节饱和度

- (IBAction)baohedu:(id)sender {

    //inputSaturation 饱和度

    [filter setValue:[NSNumber numberWithFloat:_baoheduzhi.value] forKey:@"inputSaturation"];

    [self setimage];

}


//调节亮度

- (IBAction)liangdu:(id)sender {

    //inputBrightness 亮度

    [filter setValue:[NSNumber numberWithFloat:_liangduzhi.value] forKey:@"inputBrightness"];

    [self setimage];

}

//调节对比度

- (IBAction)duibidu:(id)sender {

    //inputContrast 对比度

    [filter setValue:[NSNumber numberWithFloat:_duibiduzhi.value] forKey:@"inputContrast"];

    [self setimage];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    

}

@end


你可能感兴趣的:(objective-c 我的美图软件)