Convert.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:project-bianca 作者:
public static BufferedImage toImage(int w, int h, byte[] data) {
    DataBuffer buffer = new DataBufferByte(data, w * h);

    int pixelStride = 3; // assuming r, g, b, r, g, b,...
    int scanlineStride = 3 * w; // no extra padding
    int[] bandOffsets = { 0, 1, 2 }; // r, g, b
    WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h, scanlineStride, pixelStride, bandOffsets, null);

    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    boolean hasAlpha = false;
    boolean isAlphaPremultiplied = false;
    int transparency = Transparency.OPAQUE;
    int transferType = DataBuffer.TYPE_BYTE;
    ColorModel colorModel = new ComponentColorModel(colorSpace, hasAlpha, isAlphaPremultiplied, transparency, transferType);

    return new BufferedImage(colorModel, raster, isAlphaPremultiplied, null);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号