10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UIImageのデータをCIFilterを使って切り取る方法

Posted at

UIImageの画像を指定のサイズで切り取りたいときの話。

##準備
CoreImage.frameworkを追加し、ヘッダーファイルにインポートしておく。

.h
#import <CoreImage/CoreImage.h>

##実装
UIImageを用意する部分は省略。

.m
//UIImageをCIImageに変換
CIImage* ciImage = [[CIImage alloc]]initWithImage:uiimage];

//CIFilter生成
CIFilter* cifilter = [CIFilter filterWithName:@"CICrop"];
//トリミング開始位置と切り取るサイズ
[cifilter setValue:[CIVector vectorWithX:x
                                       Y:y
                                       Z:width
                                       W:height]
            forKey:@"inputRectangle"];
//CIFilterにCIImageのセット
[cifilter setValue:ciImage forKey:@"inputImage"];
//結果の取り出し
CIImage* filteredImage = cifilter.outputImage;

//UIImageに変換する
UIImage* resultImage = [UIImage imageWithCIImage:filteredImage];
10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?