bmp格式解析

2021-06-07 02:21:37 字數 2372 閱讀 8509

寫這**時,出現的錯誤:

1. 忘了on_wm_paint()  一直在介面上畫不出來  找了好久 

2. 正確寫法

byte* pbits = (byte*)lpbase + pbitmapfileheader->bfoffbits;
寫成了
byte* pbits =  pbitmapfileheader->bfoffbits;

.cpp

#include "readbmp.h"

#include "resource.h"

//cmainwindow

begin_message_map(cmainwindow, cwnd)

on_wm_create()

on_wm_paint()

on_command(idc_open, onopen)

end_message_map()

//建構函式

cmainwindow::cmainwindow()

//析構函式

cmainwindow::~cmainwindow()

//訊息對映函式

int cmainwindow::oncreate(lpcreatestruct lpcreatestruct)

void cmainwindow::onncdestroy( )

void cmainwindow::ondestroy()

void cmainwindow::onpaint()

void cmainwindow::onopen()

handle hfile = ::createfile(dlg.getpathname(), generic_read , file_share_read, null, open_existing, file_attribute_normal, null);

if (invalid_handle_value == hfile)

if (null == hfilemap)

lpvoid lpbase = ::mapviewoffile(hfilemap, file_map_read, 0, 0, 0);

if (null == lpbase)

//從頭結構中取三個資訊:1.bfoffbits點陣圖資料在檔案中的起始位置,2.m_nwidth影象的寬,3.m_nheight影象的高

bitmapfileheader* pbitmapfileheader;

bitmapinfo* pbitmapinfo;

pbitmapfileheader = (bitmapfileheader*)lpbase;

if (pbitmapfileheader->bftype != makeword('b','m'))

//dword bfoffbits = pbitmapfileheader->bfoffbits;

byte* pbits = (byte*)lpbase + pbitmapfileheader->bfoffbits;

pbitmapinfo = (bitmapinfo*)((byte*)lpbase + sizeof(bitmapfileheader));

m_nwidth = pbitmapinfo->bmiheader.biwidth;

m_nheight = pbitmapinfo->bmiheader.biheight;

//顯示bmp檔案到記憶體裝置

//得客戶區dc

cclientdc dc(this);

//建立與客戶區dc相容的點陣圖

hbitmap hbitmap = ::createcompatiblebitmap(dc, m_nwidth, m_nheight);

if (hbitmap == 0)

//位圖選入記憶體dc

::selectobject(m_hmemdc, hbitmap);

//影象資料放到建立的dc中

::setdibitstodevice(m_hmemdc, 0, 0, m_nwidth, m_nheight, 0, 0, 0, m_nheight, pbits, pbitmapinfo, dib_rgb_colors);

::invalidaterect(m_hwnd, null, true);

::deleteobject(hbitmap);

::unmapviewoffile(lpbase);

::closehandle(hfilemap);

::closehandle(hfile);

}

.h;

//cmainwindow

class cmainwindow:public cwnd

;

Bmp檔案格式解析

1.bmp檔案組成。bmp檔案由檔案頭 位圖資訊頭 顏色資訊和圖形資料四部分組成。檔案頭主要包含檔案的大小 檔案型別 影象資料偏離檔案頭的長度等資訊 位圖資訊頭包含圖象的尺寸資訊 影象用幾個位元數值來表示乙個畫素 影象是否壓縮 影象所用的顏色數等資訊。顏色資訊包含影象所用到的顏色表,顯示影象時需用到...

BMP之一 bmp格式解析 很容易理解

位 件 bitmap file,bmp 格式是windows採用的影象檔案儲存格式,在windows環境下執行的所有影象處理軟體都支援這種格 式。windows 3.0以前的bmp位 件格式與顯示裝置有關,因此把它稱為裝置相關位圖 device dependent bitmap,ddb 檔案格式。w...

Bmp格式與程式設計讀取解析

影象載入函式,通過bmp路徑,載入影象資料,通過類建構函式來實現。digitalimage digitalimage lpctstr lpszpath 為位 件頭分配空間,並初始化為0 m lpbmpfileheader lpbitmapfileheader new byte sizeof bitm...