简体   繁体   English

如何在Monotouch中对UIImageView进行运动模糊效果?

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

What's the way to do a realtime motion blur in MonoTouch? 在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. 像在Photoshop中一样,以强度和方向作为参数滚动惯性图片库时,需要在UIImageView上应用运动模糊效果。

I can't find any blur or motion blur filter in CocoaTouch or in CoreAnimation or anywhere in the iOS SDK. 我在CocoaTouch或CoreAnimation或iOS SDK中的任何地方都找不到任何模糊或运动模糊滤镜。

Is there some 2D effects library usable from MonoTouch with realtime blur filters that are good for the iPhone? MonoTouch是否有一些2D效果库可用于对iPhone有利的实时模糊滤镜?

Thanks in advance. 提前致谢。

I've found a good open source library to do many effects on UIImage: 我找到了一个很好的开源库,可以对UIImage进行很多处理:

https://github.com/gdawg/uiimage-dsp https://github.com/gdawg/uiimage-dsp

It also uses the Accelerated framework to speed up the things a little on iOS 4.0. 它还使用Accelerated框架在iOS 4.0上加快了速度。

Now, if only there was a MonoTouch wrapper of this... 现在,只要有一个MonoTouch包装器...

If you want to use the blur Apple demoed at WWDC (although not realtime!) I made a native port of their UIImage categories. 如果要使用在WWDC上演示的Apple模糊效果(尽管不是实时的!),我将其UIImage类别作为本机端口。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM