• Java下BufferedImage处理PNG图片的ARGB


    通过MultipartFile传入png图片,并通过BufferedImage进行处理。

    @SneakyThrows
    public void picture(MultipartFile multipartFile) {
        //读取图片
        System.out.println("正在读取...");
        BufferedImage bufferedImage = null;
        try {
            bufferedImage = ImageIO.read(multipartFile.getInputStream());
        } catch (Exception e) {
            e.printStackTrace();
        }
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        int minx = bufferedImage.getMinX();
        int miny = bufferedImage.getMinY();
        //处理图片
        System.out.println("正在处理...");
        for (int i = minx; i < width; i++) {
            for (int j = miny; j < height; j++) {
                int pixel = bufferedImage.getRGB(i, j);//获取颜色
                int alpha = pixel >> 24 & 0xff;//获取alpha
                int red = pixel & 0xff0000 >> 16;//获取红色
                int green = pixel & 0xff00 >> 8;//获取绿色
                int blue = pixel & 0xff;//获取蓝色
                int color = (alpha << 24) | (red << 16) | (green << 8) | blue;//将argb还原成整数
                bufferedImage.setRGB(i, j, color);//设置颜色
            }
        }
        //保存图片
        File file = new File("test.png");
        ImageIO.write(bufferedImage, "png", file);
        System.out.println("处理完毕...");
    }
    ** Then I looked up at the sky and saw the sun **
  • 相关阅读:
    debian 登录CUPS 管理界面报错
    Shell脚本调试技术
    贴个ALSA例程
    产业生态圈和生态圈
    开个帖,开始学习shell编程
    Lua源码阅读建议
    Flash, EEPROM, SPI Flash diff
    makefile中的notdir,wildcard和patsubst
    quartus II使用零星记录
    Hello ZED
  • 原文地址:https://www.cnblogs.com/chenyangsocool/p/14724184.html
Copyright © 2020-2023  润新知