• 图片处理羽化特效


    float mSize = 0.5f;
      public Bitmap render(Bitmap bitmap)
      {
        if(bitmap == null)return null;
    
        final int SIZE = 32768;
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int ratio = width >height ? height * SIZE /width : width * SIZE/height;//这里有额外*2^15 用于放大比率;之后的比率使用时需要右移15位,或者/2^15.
    
        int cx = width>>1;
        int cy = height>>1;
        int max = cx*cx + cy*cy;
        int min = (int)(max *(1-mSize));
        int diff= max -min;// ===>>    int diff = (int)(max * mSize);
    int[] pixels = new int[width * height]; bitmap.getPixels(pixels ,0 , width , 0 , 0 , width , height); for(int i=0 ; i<height ; i++) { for(int j=0 ; j<width ; j++) { int pixel = pixels[i*width +j]; int r = (pixel & 0x00ff0000)>>16; int g = (pixel & 0x0000ff00)>>8; int b = (pixel & 0x000000ff); int dx = cx - j; int dy = cy - i; if(width > height) { dx= (dx*ratio)>>15; } else { dy = (dy * ratio)>>15; } int dstSq = dx*dx + dy*dy; float v = ((float) dstSq / diff)*255; r = (int)(r +v); g = (int)(g +v); b = (int)(b +v); r = (r>255 ? 255 : (r<0? 0 : r)); g = (g>255 ? 255 : (g<0? 0 : g)); b = (b>255 ? 255 : (b<0? 0 : b)); pixels[i*width +j] = (pixel & 0xff000000) + (r<<16)+ (g<<8) +b; } } return Bitmap.createBitmap(pixels ,width , height , Config.ARGB_8888); }
    在PHOTOSHOP里,羽化就是使你选定范围的图边缘达到朦胧的效果。 
    
    羽化值越大,朦胧范围越宽,羽化值越小,朦胧范围越窄。可根据你想留下图的大小来调节。
    算法分析:
    1、通过对rgb值增加额外的V值实现朦胧效果
    2、通过控制V值的大小实现范围控制。
    3、V  = 255 * 当前点Point距中点距离的平方s1 / (顶点距中点的距离平方 *mSize)s2;
    4、s1 有根据 ratio 修正 dx dy值。


  • 相关阅读:
    JSONP
    懒加载
    HTTP 状态代码
    java4中创建内对象的方法
    注册jdbc驱动程序的三种方式
    java Clone()克隆
    Class.forName()的理解
    Bitmap介绍
    前端-PC端瀑布流【10张图】
    百度小程序-图片画廊-使用previewImage方法实现
  • 原文地址:https://www.cnblogs.com/lipeil/p/2696519.html
Copyright © 2020-2023  润新知