How to do a motion blur effect on an UIImageView in Monotouch?

穿精又带淫゛_ 提交于 2019-12-04 06:41:35

问题


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.


回答1:


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...




回答2:


This post describes one possible way of doing it:

http://martinbowling.com/post/Recreating-the-Awesome-UrbanSpoon-UI-Effect-In-MonoTouch.aspx




回答3:


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);


来源:https://stackoverflow.com/questions/7475610/how-to-do-a-motion-blur-effect-on-an-uiimageview-in-monotouch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!