zoukankan      html  css  js  c++  java
  • 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 **
  • 相关阅读:
    LeetCode5654. 盒子中小球的最大数量
    LeetCode40. 组合总和 II
    LeetCode39. 组合总和
    LeetCode17. 电话号码的字母组合
    Leetcode216. 组合总和 III
    eclipse相关使用
    matlab符号的含义
    matlab矩阵相关的笔记
    vi编辑器
    Linux 环境变量
  • 原文地址:https://www.cnblogs.com/chenyangsocool/p/14724184.html
Copyright © 2011-2022 走看看