Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BMP图片详解 #51

Open
johnnian opened this issue Apr 11, 2018 · 0 comments
Open

BMP图片详解 #51

johnnian opened this issue Apr 11, 2018 · 0 comments
Labels

Comments

@johnnian
Copy link
Owner

johnnian commented Apr 11, 2018

最近在研究处理BMP的文件,顺带总结下相关知识点!

BMP文件结构

    
    //byteBuffer 是图片的byte数据
    //数据区的偏移量
    byteBuffer.flip();
    byte[] dataOffsetArr = new byte[4];
    byteBuffer.position(10);
    byteBuffer.get(dataOffsetArr);
    int dataOffset = HexUtils.byteArrayToInt(dataOffsetArr, false);
    logger.info("size:" + dataOffset);

    //图像的宽度
    byte[] widthArr = new byte[4];
    byteBuffer.position(18);
    byteBuffer.get(widthArr);
    int width = HexUtils.byteArrayToInt(widthArr, false);
    logger.info("width:" + width);

    //图像的高度
    byte[] highArr = new byte[4];
    byteBuffer.position(22);
    byteBuffer.get(highArr);
    int high = HexUtils.byteArrayToInt(highArr, false);
    logger.info("width:" + high);

    //图像的深度
    byte[] depthArr = new byte[4];
    byteBuffer.position(28);
    byteBuffer.get(depthArr);
    int depth = HexUtils.byteArrayToInt(depthArr, false);
    logger.info("depth:" + depth);

    //图像的深度
    byte[] sizeArr = new byte[4];
    byteBuffer.position(34);
    byteBuffer.get(sizeArr);
    int dataSize = HexUtils.byteArrayToInt(sizeArr, false);
    logger.info("dataSize:" + dataSize);

    //数据区
    byte[] bmpData = new byte[dataSize];
    byteBuffer.position(dataOffset);
    byteBuffer.get(bmpData);

参考链接

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant