How can i blur an image?

JonathanZunigaJonathanZuniga USMember ✭✭
edited May 2015 in Xamarin.Forms

Hello, i'm trying to apply a gaussian blur effect to an image (.jpg), like this example: notes.ericwillis.com/2009/10/blur-an-image-with-csharp/
But it throw me: Error CS0246: The type or namespace name `Bitmap' could not be found. Are you missing an assembly reference? (CS0246)

I would really appreciate any help.

Best Answer

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    That Bitmap class is a Windows class. You will need to write some platform-specific code to do this because there is no cross-platform bitmap representation.

  • NoeMoralesNoeMorales USMember

    Hi Adam thank you for reply, my question is how i can do that. Can you or anyone point me in the right direction of a tutorial or sample code?

    Thanks in advance.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Do you need to actually produce a blurred image or do you just need it to appear blurred on the screen? In other words, do you care about saving the results to a file? I ask because on iOS there's a very easy way to do this (using an effect overlay), and on Android you can emulate it like this. If you use that approach then what you would do is make a custom image renderer, and that could be relatively straightforward.

  • JonathanZunigaJonathanZuniga USMember ✭✭

    @adamkemp thanks, i just need it to appear blurred on Android.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Poor you. That's the hardest platform to do it on. :)

  • JonathanZunigaJonathanZuniga USMember ✭✭

    I found two Xamarin recipes: developer.xamarin.com/recipes/android/other_ux/drawing/blur_an_image_with_renderscript/, but how do i implement it with X.Forms? :neutral:

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Take a look at this. iOS and Android don't look identical, but it's a good start. I mostly copy/pasted the base ImageRenderer code from the assembly browser because unfortunately (like much of Xamarin.Forms) it wasn't designed to be extended. A few things I had to comment out because they're internal. To make those things work might require reflection or using a totally custom Image type instead of reusing the existing one, and that might suck. Still, it seems to work. I hope that helps.

  • JonathanZunigaJonathanZuniga USMember ✭✭

    It works! really thank you very much for the solution and for the speed, you are great! :smiley:

Sign In or Register to comment.