<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 閱讀(1846) 評論(2)  編輯  收藏

    評論

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

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

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

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


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


    網站導航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     

    導航

    統計

    常用鏈接

    留言簿(110)

    我參與的團隊

    隨筆分類(126)

    隨筆檔案(155)

    文章分類(9)

    文章檔案(19)

    相冊

    搜索

    積分與排名

    最新隨筆

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲AV第一页国产精品| 亚洲熟妇成人精品一区| 中文字幕免费在线播放| 久久亚洲精品成人| 亚洲美女免费视频| 国产a v无码专区亚洲av| 国产AV无码专区亚洲精品| 亚洲乱码中文字幕综合 | 国产成人免费在线| 亚洲AV无码国产剧情| 久久精品国产69国产精品亚洲| 一二三四视频在线观看中文版免费 | 曰批免费视频播放免费| 青青草原精品国产亚洲av| 国产精品99久久免费| 9420免费高清在线视频| 免费人成再在线观看网站| 亚洲另类视频在线观看| 人妻无码久久一区二区三区免费| 亚洲国产精品ⅴa在线观看| 亚洲AV无码久久精品色欲| 国产免费av一区二区三区| 特级精品毛片免费观看| 精品一区二区三区无码免费直播 | 亚洲av永久无码精品秋霞电影秋 | 亚洲综合伊人久久综合| 免费爱爱的视频太爽了| 免费女人高潮流视频在线观看| 在线观看亚洲专区| 国产亚洲精品影视在线| 亚洲黄网站wwwwww| 亚洲无人区一区二区三区| 日韩亚洲国产二区| 成人免费视频软件网站| 3344免费播放观看视频| 青柠影视在线观看免费高清| www免费黄色网| 一级做α爱过程免费视频| 在线观看免费亚洲| 亚洲AV香蕉一区区二区三区| 精品国产成人亚洲午夜福利|