Android图像处理——浮雕效果

浮雕效果原理:

对图像像素点的像素值与相邻像素点的值相减后加127.

核心代码:

/** * 浮雕效果 * @param bitmap * @return */public static Bitmap handleEmbossEffect(Bitmap bitmap) {    int width = bitmap.getWidth();    int height = bitmap.getHeight();    int color = 0, preColor = 0, a, r, g, b;    int r1, g1, b1;    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);    int[] oldPx = new int[width * height];    int[] newPx = new int[width * height];    bitmap.getPixels(oldPx, 0, width, 0, 0, width, height);    for (int i = 1; i < oldPx.length; i++) {        preColor = oldPx[i-1];        a = Color.alpha(preColor);        r = Color.red(preColor);        g = Color.green(preColor);        b = Color.blue(preColor);        color = oldPx[i];        r1 = Color.red(color);        g1 = Color.green(color);        b1 = Color.blue(color);        r = r1 - r + 127;        g = g1 - g + 127;        b = b1 - b + 127;        if (r > 255) {            r = 255;        } else if (r < 0){            r = 0;        }        if (g > 255) {            g = 255;        } else if (g < 0){            g = 0;        }        if (b > 255) {            b = 255;        } else if (b < 0){            b = 0;        }        newPx[i] = Color.argb(a, r, g, b);    }    bmp.setPixels(newPx, 0, width, 0, 0, width, height);    return bmp;}

效果如下图所示:

原图:

效果图:

更多相关文章

  1. android anim 动画效果
  2. Android 启动页过渡动画效果实现(二)
  3. [置顶] android 抽屉效果,内容GridView来实现单行滑动
  4. Android用xml写动画效果
  5. TabHost与RadioGroup结合完成的菜单【带效果图】5个Activity
  6. SlidingMenu和ActionBarSherlock结合做出出色的App布局,Facebook
  7. Android 实现View中添加子元素的动态效果
  8. android实践项目一实现简单的验证码和spinner下拉选项效果
  9. Android模仿微信、云播雷达扫描动画效果

随机推荐

  1. android 测试
  2. 【Android】选项卡使用
  3. Android(安卓)webview HitTestResult识别
  4. Android Launcher3去除应用列表,二级菜单,
  5. ViewPagerIndicator使用
  6. Android Studio 调试工具常见问题
  7. React Native與Android交互
  8. android 获取以太网的连接状态
  9. Android中如何获得本机号码信息
  10. 整理一下Android中的ListView