ThumbnailResource.java 文件源码

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

项目:icafe 作者:
private void setThumbnailImage(ImageResourceID id, int dataType, int width, int height, int totalSize, byte[] thumbnailData) {
    // JFIF data in RGB format. For resource ID 1033 (0x0409) the data is in BGR format.
    if(dataType == Thumbnail.DATA_TYPE_KJpegRGB) {
        thumbnail.setImage(width, height, dataType, thumbnailData);
    } else if(dataType == Thumbnail.DATA_TYPE_KRawRGB) {
        // kRawRGB - NOT tested yet!
        //Create a BufferedImage
        DataBuffer db = new DataBufferByte(thumbnailData, totalSize);
        int[] off = {0, 1, 2};//RGB band offset, we have 3 bands
        if(id == ImageResourceID.THUMBNAIL_RESOURCE_PS4)
            off = new int[]{2, 1, 0}; // RGB band offset for BGR for photoshop4.0 BGR format
        int numOfBands = 3;
        int trans = Transparency.OPAQUE;

        WritableRaster raster = Raster.createInterleavedRaster(db, width, height, paddedRowBytes, numOfBands, off, null);
        ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, trans, DataBuffer.TYPE_BYTE);

        thumbnail.setImage(new BufferedImage(cm, raster, false, null));
    } else
        throw new UnsupportedOperationException("Unsupported IRB thumbnail data type: " + dataType);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号