zoukankan      html  css  js  c++  java
  • xamarin.android 图片高斯模糊效果

    代码如下:

         private static float BITMAP_SCALE = 0.1f;
            private static float BLUR_RADIUS = 12.0f;
    
            public static Bitmap Blur(Context ctx, Bitmap image)
            {
                int width =(int) Math.Round(image.Width * BITMAP_SCALE);
                int height =(int) Math.Round(image.Height * BITMAP_SCALE);
    
                Bitmap inputBitmap = Bitmap.CreateScaledBitmap(image, width, height, false);
                Bitmap outputBitmap = Bitmap.CreateBitmap(inputBitmap);
    
                RenderScript rs = RenderScript.Create(ctx);
                ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs));
                Allocation tmpIn = Allocation.CreateFromBitmap(rs, inputBitmap);
                Allocation tmpOut = Allocation.CreateFromBitmap(rs, outputBitmap);
                theIntrinsic.SetRadius(BLUR_RADIUS);
                theIntrinsic.SetInput(tmpIn);
                theIntrinsic.ForEach(tmpOut);
                tmpOut.CopyTo(outputBitmap);
    
                return outputBitmap;
            }
     var bitmap = ((BitmapDrawable)Resources.GetDrawable(Resource.Drawable.hero)).Bitmap;
    
    var blur = Blur(this, bitmap);
    var viewImage = FindViewById<ImageView>(Resource.Id.imageView1);
        viewImage.SetImageBitmap(blur); 

    效果如下:

  • 相关阅读:
    MOP tricks
    DTLZ
    箱型图Box
    IDEA代码折叠
    IDEA快捷键无法使用
    [转].gitignore文件不起作用的解决方案
    你必须知道的EF知识和经验
    采用MiniProfiler监控EF与.NET MVC项目
    EF使用CodeFirst方式生成数据库&技巧经验
    EF查询之性能优化技巧
  • 原文地址:https://www.cnblogs.com/mycing/p/5660057.html
Copyright © 2011-2022 走看看