ios


Blur an image via objective-c


I want to blur an UIImage for an app,
Does any of you have an Objective-C method to blur an image ?
I tried to find a method or a technique but couldn't find anything. Help please !
You can use core image filters.
http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html
Look at this snippet from https://gist.github.com/betzerra/5988604
// Needs CoreImage.framework
- (UIImage *)blurredImageWithImage:(UIImage *)sourceImage{
// Create our blurred image
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [CIImage imageWithCGImage:sourceImage.CGImage];
// Setting up Gaussian Blur
CIFilter *filter = [CIFilter filterWithName:#"CIGaussianBlur"];
[filter setValue:inputImage forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:15.0f] forKey:#"inputRadius"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
/* CIGaussianBlur has a tendency to shrink the image a little, this ensures it matches
* up exactly to the bounds of our original image */
CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];
UIImage *retVal = [UIImage imageWithCGImage:cgImage];
if (cgImage) {
CGImageRelease(cgImage);
}
return retVal;
}
You can use UIVisualEffectView with visual effects. Initialize an element of visualEffect and effectView than add to your view or imgview wherever you want :). Also you can choose EffectStyles.
code snippet :
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
visualEffectView.frame = YourImgView.bounds;
[YourImgView addSubview:visualEffectView];
I recommend to use Storyboard for implementing blur or vibrancy by UIVisualEffectView. For more, look at my sample project at https://github.com/Vaberer/BlurTransition to demonstrate how to it works and how use it with autolayout inside the UIVisualEffect
Swift 2.2 :
func blurredImage(with sourceImage: UIImage) -> UIImage {
let filter = CIFilter(name: "CIGaussianBlur")
filter!.setValue(CIImage(image: sourceImage), forKey: kCIInputImageKey)
filter!.setValue(0.8, forKey: kCIInputIntensityKey)
let ctx = CIContext(options:nil)
let cgImage = ctx.createCGImage(filter!.outputImage!, fromRect:filter!.outputImage!.extent)
return UIImage(CGImage:cgImage)
}
Solution :
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = self.view.bounds;
blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
//ADD BLUR EFFECT VIEW IN MAIN VIEW
[self.view addSubview:blurEffectView];

Related Links

dyld: Library not loaded: #rpath/JSONModel.framework/JSONModel
How to implement airplay in an iOS app for streaming video on Apple TV
Touch ID Passcode Integration in iOS
how to get today's date less 18 years
iOS Not able to change the frame of UITextField inputAccessoryView.superview
Publishing issue, Callkit is included even we are not using it
How to get crash information from a TestFlight launched app?
Parse: Updating relation on user in Local Datastore
iOS 10, Local notification show when app is in forground?
What is the reason for this UITableView not showing up on my view controller?
Xcode inserted fileprivate functions after updating to Swift 3 [duplicate]
Xamarin ios UItableView Empty rows at top using Task Scheduler in background
How to test iOS app's localization on a real device when using appium?
How to prevent NSInternalInconsistencyException with Realm and UICollectionView
(Swift, EarlGrey) move slider to the middle
How can I make physicBody dynamic only on needed levels?

Categories

HOME
sbt
ssis
graph
simulated-annealing
office-js
copy
jsonschema
styling
localforage
cql3
arm
textbox
wso2is
entity
r-caret
push
sqlconnection
aac
deserialization
python-2.5
monaco-editor
aar
libssh
jmeter-plugins
sencha-touch-2
line-breaks
broker
urlrewriter.net
addthis
google-oauth2
grouping
listbox
apscheduler
expression-trees
silverlight-5.0
clappr
json-c
udid
stomp
detach
roo
zipline
windows-scripting
jpype
hawkular
gradle-tooling-api
wp-api
karnaugh-map
multisite
stroke
okular
replaygain
kony
abbyy
sshd
cmsmadesimple
glumpy
android-camera-intent
dr-memory
jasny-bootstrap
statistics-bootstrap
ng-annotate
android-number-picker
fab
mtp
julian
treegrid
janino
slick2d
tortoisecvs
symfony-2.5
catalina.out
zeroclipboard
nhunspell
data-quality
bson
dirpagination
notifyicon
xidel
resolver
datapump
webcal
virtual-earth
impdp
icon-fonts
cloud-hosting
wescheme
rpn
arden-syntax
boost-gil
combinators
having
directoryentry
jdic
custom-tag
gendarme
web-based

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App