What's the way to do a realtime motion blur in MonoTouch?
I need to apply a motion blur effect on an UIImageView when scrolling an inertial picture gallery, with strength and direction as parameters, as in Photoshop.
I can't find any blur or motion blur filter in CocoaTouch or in CoreAnimation or anywhere in the iOS SDK.
Is there some 2D effects library usable from MonoTouch with realtime blur filters that are good for the iPhone?
Thanks in advance.
I've found a good open source library to do many effects on UIImage:
https://github.com/gdawg/uiimage-dsp
It also uses the Accelerated framework to speed up the things a little on iOS 4.0.
Now, if only there was a MonoTouch wrapper of this...
This post describes one possible way of doing it:
http://martinbowling.com/post/Recreating-the-Awesome-UrbanSpoon-UI-Effect-In-MonoTouch.aspx
If you want to use the blur Apple demoed at WWDC (although not realtime!) I made a native port of their UIImage categories.
- https://github.com/lipka/MonoTouch.UIImageEffects
Getting the blur is a little tedious, but doable:
// Helper method to create an image snapshot of the view hierarchy
UIImage SnapshotImageWithScale (UIView view, float scale)
{
UIGraphics.BeginImageContextWithOptions (view.Bounds.Size, false, scale);
view.DrawViewHierarchy (view.Bounds, true);
UIImage image = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
return image;
}
...
// Create snapshot of the parent view controller (this can be the superview or anything else)
UIImage snapshot = SnapshotImageWithScale (parentView, UIScreen.MainScreen.Scale);
// Blur the snapshot with the specified radius and tint color
snapshot = snapshot.ApplyBlur (6.0f, UIColor.FromWhiteAlpha (0.0f, 0.6f), 0.8f, null);
// Create an UIImageView to display the blurred snapshot
UIImageView snapshotView = new UIImageView {
Frame = new RectangleF (0, 0, View.Bounds.Width, View.Bounds.Height),
Image = snapshot,
};
View.AddSubview (snapshotView);