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);
}
Convert.java 文件源码
java
阅读 20
收藏 0
点赞 0
评论 0
项目:project-bianca
作者:
评论列表
文章目录