<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    David.Turing's blog

     

    Java讀取BMP文件

    各位老大,幫我看看代碼

    ???????? // ?The?DataInputStream?allows?you?to?read?in?16?and?32?bit?numbers
    ????????DataInputStream?in? = ? new ?DataInputStream(instream);
    ????????DataOutputStream?out
    = new ?DataOutputStream(outstream);

    ????????
    // ?Verify?that?the?header?starts?with?'BM'
    ???????? if ?(in.read()? != ? ' B ' )? {
    ????????????
    throw ? new ?IOException( " Not?a?.BMP?file " );
    ????????}

    ????????out.write(
    ' B ' );
    ????????
    ????????
    if ?(in.read()? != ? ' M ' )? {
    ????????????
    throw ? new ?IOException( " Not?a?.BMP?file " );
    ????????}

    ????????out.write(
    ' M ' );
    ????????
    ????????
    // ?????Get?the?total?file?size
    ???????? int ?fileSize? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(fileSize));

    ????????
    // ?????Skip?the?2?16-bit?reserved?words
    ????????out.writeShort(in.readUnsignedShort());
    ????????out.writeShort(in.readUnsignedShort());

    ????????
    int ?bitmapOffset? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(bitmapOffset));
    ????????
    int ?bitmapInfoSize? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(bitmapInfoSize));
    ????????
    ????????
    int ?width? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(width));
    ????????
    int ?height? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(height));
    ????????
    // ?Skip?the?16-bit?bitplane?size
    ????????out.writeShort(in.readUnsignedShort());
    ????????
    int ?bitCount? = ?intelShort(in.readUnsignedShort());
    ????????out.writeShort(intelShort(bitCount));
    ????????
    int ?compressionType? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(compressionType));
    ????????
    int ?imageSize? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(imageSize));
    // ?Skip?pixels?per?meter
    ????????out.writeInt(in.readInt());
    ????????out.writeInt(in.readInt());

    ????????
    int ?colorsUsed? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(colorsUsed));
    ????????
    int ?colorsImportant? = ?intelInt(in.readInt());
    ????????out.writeInt(intelInt(colorsImportant));
    ????????System.out.println(
    " [colorused]= " + colorsUsed);

    // ?Read?the?pixels?from?the?stream?based?on?the?compression?type
    ???????? if ?(compressionType? == ?BI_RGB)? {
    ????????????
    if ?(bitCount? == ? 24 )? {
    ????????????????readRGB24(width,?height,?in,?out);
    ????????????}

    ????????}
    ?
    ????}


    ???? protected ? static ? void ?readRGB24( int ?width,? int ?height,
    ????????DataInputStream?in,?OutputStream?out)
    ????
    throws ?IOException
    ????
    {

    // ?Start?storing?at?the?bottom?of?the?array
    ???????? for ?( int ?h? = ?height - 1 ;?h? >= ? 0 ;?h -- )? {
    ?????????
    for ?( int ?w? = ? 0 ;?w? < ?width;?w ++ )? {

    // ?Read?in?the?red,?green,?and?blue?components
    ?????????? int ?red? = ?in.read();
    ??????????
    int ?green? = ?in.read();
    ??????????
    int ?blue? = ?in.read();
    ??????????out.write(red);
    ??????????out.write(green);
    ??????????out.write(blue);
    ????????????}

    ????????}

    ????}

    posted on 2006-06-06 10:29 david.turing 閱讀(1851) 評論(2)  編輯  收藏

    評論

    # re: Java讀取BMP文件 2007-11-07 17:45 zouni

    哪里抄過來的代碼?  回復  更多評論   

    # re: Java讀取BMP文件 2007-11-07 17:52 david.turing

    我暈,沒有publish到blog的文章也能google到?  回復  更多評論   


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(110)

    我參與的團隊

    隨筆分類(126)

    隨筆檔案(155)

    文章分類(9)

    文章檔案(19)

    相冊

    搜索

    積分與排名

    最新隨筆

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 久久国产成人精品国产成人亚洲| 亚洲第一区在线观看| 亚洲日本在线电影| mm1313亚洲精品国产| 一个人免费视频观看在线www| 亚洲视频欧洲视频| 日韩激情淫片免费看| 黄网站在线播放视频免费观看| 国产一卡2卡3卡4卡无卡免费视频 国产一卡二卡3卡四卡免费 | 亚洲六月丁香六月婷婷蜜芽| 桃子视频在线观看高清免费视频| 亚洲AV日韩AV天堂一区二区三区| 国产免费无码一区二区| 精品亚洲成a人片在线观看少妇| 最近最好最新2019中文字幕免费| 亚洲视频精品在线观看| 成人毛片免费网站| 人人狠狠综合久久亚洲| 亚洲第一页日韩专区| 久久毛片免费看一区二区三区| 亚洲日韩乱码中文无码蜜桃臀网站| a在线视频免费观看| 亚洲欧洲日韩综合| 天天干在线免费视频| 牛牛在线精品免费视频观看| 区久久AAA片69亚洲| 久久免费国产视频| 亚洲AV成人无码天堂| 国产一区二区三区免费视频| 中文字幕在线免费视频| 亚洲成人午夜在线| 成人免费a级毛片无码网站入口| 国产天堂亚洲精品| 亚洲av色福利天堂| 成年18网站免费视频网站| 日韩在线观看免费| 亚洲一区二区三区高清| 日韩免费三级电影| 国产一级片免费看| 亚洲国产精品嫩草影院| 亚洲国产精品久久久天堂|