您当前的位置: 首页 >  android

lichong951

暂无认证

  • 1浏览

    0关注

    131博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Android】Bitmap图像色彩模式:黑白、模糊、老照片、胶卷等(92/100)

lichong951 发布时间:2022-07-27 08:41:45 ,浏览量:1

在这里插入图片描述

图像转换封装工具类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             
关注
打赏
1659512212
查看更多评论
0.0900s