Android图像处理_浮雕效果
16lz
2021-01-23
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;}
效果如下图所示:
原图:
效果图:
更多相关文章
- android anim 动画效果
- Android 启动页过渡动画效果实现(二)
- [置顶] android 抽屉效果,内容GridView来实现单行滑动
- Android用xml写动画效果
- TabHost与RadioGroup结合完成的菜单【带效果图】5个Activity
- SlidingMenu和ActionBarSherlock结合做出出色的App布局,Facebook
- Android 实现View中添加子元素的动态效果
- android实践项目一实现简单的验证码和spinner下拉选项效果
- Android模仿微信、云播雷达扫描动画效果