objective-c 個人美圖軟件


//  ViewController.mui

//  個人美圖軟件spa

//.net

//  Created by DC017 on 16/1/5.3d

//  Copyright © 2016 DC017. All rights reserved.orm

//圖片


#import "ViewController.h"get


@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>input

{   //相冊視圖控制器it

    UIImagePickerController * imagePickerController;io

    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

相關文章
相關標籤/搜索