首页javaimageJava Graphics - 如何从字节数组中提取图像的宽度,高度,颜色和类型

Java Graphics - 如何从字节数组中提取图像的宽度,高度,颜色和类型

我们想知道如何从字节数组中提取图像的宽度,高度,颜色和类型。
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;


public class Main{

    public static void main(String[] args) throws IOException {
        byte[] picture = new byte[2048]; // your image data

        InputStream in = new ByteArrayInputStream(picture);

        BufferedImage buf = ImageIO.read(in);
        ColorModel model = buf.getColorModel();
        int height = buf.getHeight();
        int width = buf.getWidth();
    }

}