图像转换封装工具类BitmapUtil:
/**
* 图片位图转换工具
*
* @author lichong
* 2022年07月26日15:35:16
*/
public class BitmapUtil {
public static final String TAG = BitmapUtil.class.getSimpleName();
// 把位图数据保存到指定路径的图片文件
public static void saveImage(String path, Bitmap bitmap) {
// 根据指定的文件路径构建文件输出流对象
try (FileOutputStream fos = new FileOutputStream(path)) {
// 把位图数据压缩到文件输出流中
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
} catch (Exception e) {
e.printStackTrace();
}
}
// 图片黑白效果
public static Bitmap convertBlack(Bitmap origin) {
int width = origin.getWidth(); // 获取位图的宽
int height = origin.getHeight(); // 获取位图的高
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
int[] pixels = new int[width * height]; // 通过位图的大小创建像素点数组
origin.getPixels(pixels, 0, width, 0, 0, width, height);
int alpha = 0xFF 8);
int blue = (grey & 0x000000FF);
grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
grey = alpha | (grey 8) & 0xff; // 调整绿色
tb += rgb & 0xff; // 调整蓝色
}
for (int x = 0; x > 8;
tb += (rgb1 & 0xff) - (rgb2 & 0xff);
outIndex += height;
}
inIndex += width;
}
}
public static void blurFractional(int[] in, int[] out, int width, int height, float radius) {
radius -= (int) radius;
float f = 1.0f / (1 + 2 * radius);
int inIndex = 0;
for (int y = 0; y 24) & 0xff;
int r1 = (rgb1 >> 16) & 0xff;
int g1 = (rgb1 >> 8) & 0xff;
int b1 = rgb1 & 0xff;
int a2 = (rgb2 >> 24) & 0xff;
int r2 = (rgb2 >> 16) & 0xff;
int g2 = (rgb2 >> 8) & 0xff;
int b2 = rgb2 & 0xff;
int a3 = (rgb3 >> 24) & 0xff;
int r3 = (rgb3 >> 16) & 0xff;
int g3 = (rgb3 >> 8) & 0xff;
int b3 = rgb3 & 0xff;
a1 = a2 + (int) ((a1 + a3) * radius);
r1 = r2 + (int) ((r1 + r3) * radius);
g1 = g2 + (int) ((g1 + g3) * radius);
b1 = b2 + (int) ((b1 + b3) * radius);
a1 *= f;
r1 *= f;
g1 *= f;
b1 *= f;
out[outIndex] = (a1
关注
打赏
热门博文
- 【Android】手写签名(87/100)
- 【微信小程序】NFC 标签打开小程序
- 【Android】Drawable文字字体(88/100)
- 【Android】Drawable裁剪圆形、椭圆、圆角矩形图片(89/100)
- 【微信小程序】【AR】threejs-miniprogram 安装(76/100)
- 【Android】Bitmap图片旋转、缩放、翻转等变换(90/100)
- 【Android】Bitmap图片裁剪(91/100)
- 【Android】Bitmap图像色彩模式:黑白、模糊、老照片、胶卷等(92/100)
- 【Android】ImageView水波效果(93/100)
- 【Android】ImageView图片装饰 文字、水印、边框(94/100)