public static BufferedImage pixelsToImage(byte[] data, int w, int h) {
DataBuffer buffer = new DataBufferByte(data, w * h);
int pixelStride = 1; // assuming r, g, b,
// skip, r, g, b,
// skip...
int scanlineStride = w; // no extra
// padding
int[] bandOffsets = { 0 }; // r, g, b
WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h,
scanlineStride, pixelStride, bandOffsets, null);
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
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);
}
ImageOperations.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:cmoct-sourcecode
作者:
评论列表
文章目录