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

发布于 2024-12-05 18:39:10 字数 252 浏览 0 评论 0原文

在 MonoTouch 中进行实时运动模糊的方法是什么?

当滚动惯性图片库时,我需要在 UIImageView 上应用运动模糊效果,以强度和方向作为参数,就像在 Photoshop 中一样。

我在 CocoaTouch 或 CoreAnimation 或 iOS SDK 中的任何位置都找不到任何模糊或运动模糊滤镜。

MonoTouch 是否有一些 2D 效果库可供使用,带有实时模糊滤镜,适用于 iPhone?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千と千尋 2024-12-12 18:39:10

我找到了一个很好的开源库来对 UIImage 做很多效果:

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

它还使用 Accelerated 框架来稍微加快 iOS 4.0 上的速度。

现在,如果有一个 MonoTouch 包装器就好了……

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

从此见与不见 2024-12-12 18:39:10

如果你想使用 Apple 在 WWDC 上演示的模糊效果(尽管不是实时的!),我制作了他们的 UIImage 类别的本机端口。

获得模糊有点乏味,但可行:

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

If you want to use the blur Apple demoed at WWDC (although not realtime!) I made a native port of their UIImage categories.

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文