How to gaussian blur an image in MAUI?

JiuLing 1 Reputation point
2022-05-18T05:31:23.497+00:00

How to gaussian blur an image in MAUI?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,844 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,016 Reputation points Microsoft Vendor
    2022-05-20T08:45:13.157+00:00

    Hello,​

    You can customize .NET MAUI Image with handlers.

    For android,
    Before android 12, you can create a Blurred Bitmap like CreateBlurredImage method in following thread, then use SetImageBitmap(bitmap); to set the blurred bitmap
    https://github.com/xamarin/docs-archive/tree/master/Recipes/android/other_ux/drawing/blur_an_image_with_renderscript

    Android 12 or later, you can set it directly with handler.PlatformView.SetRenderEffect(RenderEffect.CreateBlurEffect(5f,50f, Shader.TileMode.Decal));

    For iOS, please create CGImage and set CIGaussianBlur like following code. Then return this BlurredImageView in CreatePlatformView.

       private class BlurredImageView : UIImageView    
              {    
                  public override UIImage Image    
                  {    
                              var MyContext = CIContext.Create();  
                              var inputImage = CIImage.FromCGImage(value.CGImage);  
                              var filter = new CIGaussianBlur() { Image = inputImage, Radius = 4 };  
                              var resultImage = MyContext .CreateCGImage(filter.OutputImage, inputImage.Extent)            
                              return new UIImage(resultImage);                                               
                      }    
                  }    
              }  
    

    For winUI, you can use GaussianBlurEffect Properties to achieve it.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments