私のiPhoneアプリケーションでは、私は白黒のUIImage
を持っています。私はその画像をぼかす必要があります(ガウスのぼかしは)。iPhone:Blur UIImage
iPhoneは、画像をぼかしする方法をよく知っています(it does that when it draws shadows)。
しかし、APIに関連するものは見つかりませんでした。
ハードウェアアクセラレーションなしで手でぼかしを行う必要がありますか?
私のiPhoneアプリケーションでは、私は白黒のUIImage
を持っています。私はその画像をぼかす必要があります(ガウスのぼかしは)。iPhone:Blur UIImage
iPhoneは、画像をぼかしする方法をよく知っています(it does that when it draws shadows)。
しかし、APIに関連するものは見つかりませんでした。
ハードウェアアクセラレーションなしで手でぼかしを行う必要がありますか?
基本的に、ぼかし効果を実装するためのストレートフォワードAPIはありません。これを達成するにはピクセルを処理する必要があります。
iPhoneはグラデーションを使用してシャドウを描画し、ぼかしは使用しません。
画像をぼかすには、畳み込み行列を使用します。ここに畳み込み行列を適用するためのsample codeがあり、ここにはoverview of convolution matricesといくつかのサンプル行列(ぼかしとガウスのぼかしを含む)があります。
(hereを見つけた)、これを試してみてください:
@interface UIImage (ImageBlur)
- (UIImage *)imageWithGaussianBlur;
@end
@implementation UIImage (ImageBlur)
- (UIImage *)imageWithGaussianBlur {
float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162};
// Blur horizontally
UIGraphicsBeginImageContext(self.size);
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[0]];
for (int x = 1; x < 5; ++x) {
[self drawInRect:CGRectMake(x, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[x]];
[self drawInRect:CGRectMake(-x, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[x]];
}
UIImage *horizBlurredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Blur vertically
UIGraphicsBeginImageContext(self.size);
[horizBlurredImage drawInRect:CGRectMake(0, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[0]];
for (int y = 1; y < 5; ++y) {
[horizBlurredImage drawInRect:CGRectMake(0, y, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[y]];
[horizBlurredImage drawInRect:CGRectMake(0, -y, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[y]];
}
UIImage *blurredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//
return blurredImage;
}
そして、このようにそれを使用する:ちょうど2倍以上にこの効果を適用し、より強いぼかしを取得するには
UIImage *blurredImage = [originalImage imageWithGaussianBlur];
:)
た後過去の同じ問題です。このライブラリをチェックしてください:
https://github.com/tomsoft1/StackBluriOS
も非常に使いやすい:
UIImage *newIma=[oldIma stackBlur:radius];
はCIFilterを経由して仕事に近づいて考えてみましょう: