91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 336KB
    文件類型: .7z
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-09
  • 語(yǔ)言: C/C++
  • 標(biāo)簽: C??圖像處理??保存??

資源簡(jiǎn)介

用C語(yǔ)言寫個(gè)應(yīng)用程序(命令行運(yùn)行的就行)提取24bit bmp圖像數(shù)據(jù),以RGB888保存成圖像數(shù)組

資源截圖

代碼片段和文件信息

#include?“Bitmap.h“



FILE?*hFile?=?NULL;

int?LoadBitmapFile?(?char?*fileName?BITMAP_IMAGE_PTR?bitmap?)
{
int?hImageFile?=?0; //?the?file?stream?of?the?bitmap?file
unsigned?char?*workingBuffer?=?0; //?use?to?hold?the?data

//?Open?the?bitmap?file
hImageFile?=?_open?(?fileName?_O_RDONLY?);

if?(?!hImageFile?)
{
WriteLogFile?(?“LoadBitmapFile?function?error!?\nCan?not?open?the?bitmap.\n“?);
return?0;

}//?End?If

//?Read?the?header?portion?of?the?bitmap?file
_read?(?hImageFile?&bitmap->bitmapHeader?sizeof?(?BITMAP_HEADER?)?);

//?test?if?it?is?a?bitmap
if?(?bitmap->bitmapHeader.uiType?!=?UNIVERSAL_BITMAP_ID?)
{
WriteLogFile?(?“LoadBitmapFile?function?error!?\n\t?this?not?a?bitmap.\n%s\n“?fileName?);
_close?(?hImageFile?);
return?0;

}//?End?If

//?Read?the?info?portion?of?the?bitmap?file
_read?(?hImageFile?&bitmap->bitmapInformation?sizeof?(?BITMAP_INFORMATION?)?);

//?load?the?data?itself?now?move?the?file?pointer?to?the?data?region
//?move?back?from?the?end?of?the?file?offset?is?set?to?the?size?of?the?specified?image
_lseek?(?hImageFile?-(int)(bitmap->bitmapInformation.biSizeImage)?SEEK_END?);

//?load?the?data?into?buffer
workingBuffer?=?(unsigned?char*)malloc?(?bitmap->bitmapInformation.biSizeImage?);
bitmap->pixelData?=?(unsigned?char*)malloc?(?bitmap->bitmapInformation.biSizeImage?);
ZeroMemory?(?bitmap->pixelData?bitmap->bitmapInformation.biSizeImage?);

if?(?!workingBuffer?||?!bitmap->pixelData?)
{
WriteLogFile?(?“LoadBitmapFile?function?error!?\n\tCan?not?allocate?memory?for?the?buffer?\n“?);
_close?(?hImageFile?);
return?0;

}//?End?If

_read?(?hImageFile?workingBuffer?bitmap->bitmapInformation.biSizeImage?);

//?now?extract?the?data
long?width??=?bitmap->bitmapInformation.biWidth;
long?height?=?bitmap->bitmapInformation.biHeight;
unsigned?long?int?dwBit?=?bitmap->bitmapInformation.biBitCount;
long?bytesPerLine?=?(width*(bitmap->bitmapInformation.biBitCount/8)?+?3)?&?(~3);

//?Test?if?the?bitmap?is?avaiable?or?not
if?(?dwBit?!=?24?&&?dwBit?!=?32?)
{
WriteLogFile?(?“LoadBitmapFile?function?error!?\n%s\tDo?not?support?this?kind?of?bitmap?\n“?fileName?);
_close?(?hImageFile?);
free?(?workingBuffer?);
free?(?bitmap->pixelData?);
return?0;

}//?End?If

//?Flip?the?image
for?(?int?y?=?0;?y? {
memcpy?(?&bitmap->pixelData[y*bytesPerLine]?
?????&workingBuffer[(height-1-y)*bytesPerLine]?
?????bytesPerLine?);

}//?End?For?(?Each?line?)

_close?(?hImageFile?);
free?(?workingBuffer?);

WriteLogFile?(?“%s?has?been?loaded?successfully!?\n“?fileName?);

return?1;
}



void?WriteLogFile?(?char?*content?...?)
{
char?buffer[1024]?=?{0}; //?the?working?buffer
va_list?argumentList?=?NULL; //variable?of?the?argument?list

if?(?!hFile?||?!content?)
return?;

va_start?(?argumentList?content?);
vsprintf?(?buffer?content?argumentList?);

評(píng)論

共有 條評(píng)論

相關(guān)資源