資源簡(jiǎn)介
數(shù)字圖像二值化的源代碼,比較簡(jiǎn)單,基于VC++實(shí)現(xiàn)

代碼片段和文件信息
//??dibapi.cpp
//??Download?by?http://www.codefans.net
//??Source?file?for?Device-Independent?Bitmap?(DIB)?API.??Provides
//??the?following?functions:
//
//??PaintDIB()??????????-?Painting?routine?for?a?DIB
//??CreateDIBPalette()??-?Creates?a?palette?from?a?DIB
//??FindDIBBits()???????-?Returns?a?pointer?to?the?DIB?bits
//??DIBWidth()??????????-?Gets?the?width?of?the?DIB
//??DIBHeight()?????????-?Gets?the?height?of?the?DIB
//??PaletteSize()???????-?Gets?the?size?required?to?store?the?DIB‘s?palette
//??DIBNumColors()??????-?Calculates?the?number?of?colors
//????????????????????????in?the?DIB‘s?color?table
//??CopyHandle()????????-?Makes?a?copy?of?the?given?global?memory?block
//
//?This?is?a?part?of?the?Microsoft?Foundation?Classes?C++?library.
//?Copyright?(C)?1992-1998?Microsoft?Corporation
//?All?rights?reserved.
//
//?This?source?code?is?only?intended?as?a?supplement?to?the
//?Microsoft?Foundation?Classes?Reference?and?related
//?electronic?documentation?provided?with?the?library.
//?See?these?sources?for?detailed?information?regarding?the
//?Microsoft?Foundation?Classes?product.
#include?“stdafx.h“
#include?“dibapi.h“
#include?
#include?
#include?
#include?
/*
?*?Dib?Header?Marker?-?used?in?writing?DIBs?to?files
?*/
#define?DIB_HEADER_MARKER???((WORD)?(‘M‘?<8)?|?‘B‘)
/*************************************************************************
??Function:??ReadDIBFile?(CFile&)
???Purpose:??Reads?in?the?specified?DIB?file?into?a?global?chunk?of
?memory.
???Returns:??A?handle?to?a?dib?(hDIB)?if?successful.
?NULL?if?an?error?occurs.
??Comments:??BITMAPFILEHEADER?is?stripped?off?of?the?DIB.??Everything
?from?the?end?of?the?BITMAPFILEHEADER?structure?on?is
?returned?in?the?global?memory?handle.
*************************************************************************/
HDIB?WINAPI?ReadDIBFile(LPCTSTR?pszFileName?)
{
BITMAPFILEHEADER?bmfHeader;
DWORD?dwBitsSize;
HDIB?hDIB;
LPSTR?pDIB;
HANDLE?hFile;
DWORD?nBytesRead;
/*
?*?get?length?of?DIB?in?bytes?for?use?when?reading
?*/
hFile?=??CreateFile(
pszFileName????//?pointer?to?name?of?the?file
GENERIC_READ???//?access?(read-write)?mode
FILE_SHARE_READ????//?share?mode
NULL???//?pointer?to?security?descriptor
OPEN_EXISTING??//?how?to?create
FILE_ATTRIBUTE_NORMAL??//?file?attributes
NULL????//?handle?to?file?with?attributes?to?copy
???);
dwBitsSize?=?GetFileSize(hFileNULL);
/*
?*?Go?read?the?DIB?file?header?and?check?if?it‘s?valid.
?*/
//?attempt?an?asynchronous?read?operation
if(!?ReadFile(hFile?(LPSTR)&bmfHeader?sizeof(bmfHeader)?&nBytesRead
?NULL))
return?NULL;
if?(bmfHeader.bfType?!=?DIB_HEADER_MARKER)
return?NULL;
/*
?*?Allocate?memory?for?DIB
?*/
hDIB?=?(HDIB)?::GlobalAlloc(GMEM_MOVEABLE?|?GMEM_ZEROINIT?dwBitsSize);
if?(hDIB?==?0)
{
return?NULL;
}
pDIB?=?(LPSTR)?::GlobalLock((HGLOBAL)?hDIB);
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
-----------?---------??----------?-----??----
???????????????151969????????????????????33
評(píng)論
共有 條評(píng)論