locked
How can i blur an image? RRS feed

  • Question

  • User102552 posted

    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.

    Tuesday, May 12, 2015 10:29 PM

Answers

  • User181 posted

    Update: I changed the iOS implementation to use CoreImage to better mirror the Android version, and I cleaned up the Android version a bit to do everything that the default renderer does (I think). It's still brittle because I'm duplicating code, and I'm using reflection for a bit of it. Still, it seems to work. Enjoy!

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, May 14, 2015 3:36 AM

All replies

  • User181 posted

    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.

    Tuesday, May 12, 2015 11:13 PM
  • User110510 posted

    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.

    Wednesday, May 13, 2015 3:34 PM
  • User181 posted

    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.

    Wednesday, May 13, 2015 3:51 PM
  • User102552 posted

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

    Wednesday, May 13, 2015 4:42 PM
  • User181 posted

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

    Wednesday, May 13, 2015 4:45 PM
  • User102552 posted

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

    Wednesday, May 13, 2015 5:41 PM
  • User181 posted

    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.

    Wednesday, May 13, 2015 11:13 PM
  • User181 posted

    Update: I changed the iOS implementation to use CoreImage to better mirror the Android version, and I cleaned up the Android version a bit to do everything that the default renderer does (I think). It's still brittle because I'm duplicating code, and I'm using reflection for a bit of it. Still, it seems to work. Enjoy!

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, May 14, 2015 3:36 AM
  • User102552 posted

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

    Thursday, May 14, 2015 10:15 PM