VC++自编图像处理程序错误fatal error C1189: #error

VC++自编图像处理程序错误fatal error C1189: #error,第1张

可能问题是你所声明函数没有定义,即你声明了一个函数却没有实现这个函数。

你可以把函数的声明和定义都放在一个文件里试试。或者把函数定义文件.cpp也包含在主调函数的文件里。

更多具体情况还得看你的代码。

BOOL ColortoGrayScale(HWND hWnd)//灰度变换

{

DWORD SrcBufSize,DstBufSize,DstLineBytes

LPBITMAPINFOHEADER lpImgData

LPSTR lpPtr

HLOCAL hTempImgData

LPBITMAPINFOHEADER lpTempImgData

LPSTR lpTempPtr

HDChDc

HFILE hf

LONG x,y

BITMAPFILEHEADER DstBf

BITMAPINFOHEADER DstBi

LOGPALETTE *pPal

HPALETTE hPrevPalette

HLOCAL hPal

DWORD NewNumColors

WORD NewBitCount

float Y

DWORD i

unsigned char Red,Green,Blue,Gray

NewNumColors=NumColors

NewBitCount=bi.biBitCount

if(NumColors==0) //真彩色

{

NewNumColors=256

NewBitCount=8

}

DstLineBytes=(DWORD)WIDTHBYTES(bi.biWidth*NewBitCount)

DstBufSize=(DWORD)(sizeof(BITMAPINFOHEADER)+NewNumColors*sizeof(RGBQUAD)+(DWORD)DstLineBytes*bi.biHeight)

memcpy((char *)&DstBf,(char *)&bf,sizeof(BITMAPFILEHEADER))

memcpy((char *)&DstBi,(char *)&bi,sizeof(BITMAPINFOHEADER))

DstBf.bfSize=DstBufSize+sizeof(BITMAPFILEHEADER)

DstBf.bfOffBits=(DWORD)(NewNumColors*sizeof(RGBQUAD)+sizeof(BITMAPFILEHEADER)

+sizeof(BITMAPINFOHEADER))

DstBi.biClrUsed=0

DstBi.biBitCount=NewBitCount

SrcBufSize=bf.bfSize-sizeof(BITMAPFILEHEADER)

if((hTempImgData=LocalAlloc(LHND,DstBufSize))==NULL)

{

MessageBox(hWnd,"Error alloc memory!","Error Message",MB_OK|MB_ICONEXCLAMATION)

return FALSE

}

lpImgData=(LPBITMAPINFOHEADER)GlobalLock(hImgData)

lpTempImgData=(LPBITMAPINFOHEADER)LocalLock(hTempImgData)

//拷贝图片

memcpy(lpTempImgData,lpImgData,DstBufSize)

//重画

memcpy(lpTempImgData,(char *)&DstBi,sizeof(BITMAPINFOHEADER))

lpPtr=(char *)lpImgData+sizeof(BITMAPINFOHEADER)

lpTempPtr=(char *)lpTempImgData+sizeof(BITMAPINFOHEADER)

hPal=LocalAlloc(LHND,sizeof(LOGPALETTE) + NewNumColors* sizeof(PALETTEENTRY))

pPal =(LOGPALETTE *)LocalLock(hPal)

pPal->palNumEntries =(WORD) NewNumColors

pPal->palVersion= 0x300

if(NumColors==0) //真彩色

for (i = 0i <256i++) {

pPal->palPalEntry[i].peRed=(BYTE)i

pPal->palPalEntry[i].peGreen=(BYTE)i

pPal->palPalEntry[i].peBlue=(BYTE)i

pPal->palPalEntry[i].peFlags=(BYTE)0

*(lpTempPtr++)=(unsigned char)i

*(lpTempPtr++)=(unsigned char)i

*(lpTempPtr++)=(unsigned char)i

*(lpTempPtr++)=0

}

else

for (i = 0i <NewNumColorsi++) {

Blue=(unsigned char )(*lpPtr++)

Green=(unsigned char )(*lpPtr++)

Red=(unsigned char )(*lpPtr++)

Y=(float)((Red*30+Green*59+Blue*11+50)/100)

Gray=(BYTE)Y

lpPtr++

pPal->palPalEntry[i].peRed=Gray

pPal->palPalEntry[i].peGreen=Gray

pPal->palPalEntry[i].peBlue=Gray

pPal->palPalEntry[i].peFlags=0

*(lpTempPtr++)=(unsigned char)Gray

*(lpTempPtr++)=(unsigned char)Gray

*(lpTempPtr++)=(unsigned char)Gray

*(lpTempPtr++)=0

}

if(hPalette!=NULL)

DeleteObject(hPalette)

hPalette=CreatePalette(pPal)

LocalUnlock(hPal)

LocalFree(hPal)

hDc=GetDC(hWnd)

if(hPalette){

hPrevPalette=SelectPalette(hDc,hPalette,FALSE)

RealizePalette(hDc)

}

if(NumColors==0)

for(y=0y<bi.biHeighty++){

lpPtr=(char *)lpImgData+(SrcBufSize-LineBytes-y*LineBytes)

lpTempPtr=(char *)lpTempImgData+(DstBufSize-DstLineBytes-y*DstLineBytes)

for(x=0x<bi.biWidthx++){

Blue=(unsigned char )(*lpPtr++)

Green=(unsigned char )(*lpPtr++)

Red=(unsigned char )(*lpPtr++)

Y=(float)((Red*50+Green*39+Blue*3+50)/100)//这里更改权重或者公式

Gray=(BYTE)Y

*(lpTempPtr++)=(unsigned char)Gray

}

}

if(hBitmap!=NULL)

DeleteObject(hBitmap)

hBitmap=CreateDIBitmap(hDc, (LPBITMAPINFOHEADER)lpTempImgData, (LONG)CBM_INIT,

(LPSTR)lpTempImgData+sizeof(BITMAPINFOHEADER) +NewNumColors*sizeof(RGBQUAD),

(LPBITMAPINFO)lpTempImgData, DIB_RGB_COLORS)

if(hPalette &&hPrevPalette){

SelectPalette(hDc,hPrevPalette,FALSE)

RealizePalette(hDc)

}

hf=_lcreat("c:\\Gray.bmp",0)

_lwrite(hf,(LPSTR)&DstBf,sizeof(BITMAPFILEHEADER))

_lwrite(hf,(LPSTR)lpTempImgData,DstBufSize)

_lclose(hf)

ReleaseDC(hWnd,hDc)

LocalUnlock(hTempImgData)

LocalFree(hTempImgData)

GlobalUnlock(hImgData)

return TRUE

}

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

BOOL Erosion(HWND hWnd,BOOL Hori)//图像腐蚀

{

DWORD BufSize

LPBITMAPINFOHEADER lpImgData

LPSTR lpPtr

HLOCAL hTempImgData

LPBITMAPINFOHEADER lpTempImgData

LPSTR lpTempPtr

HDChDc

HFILE hf

LONG x,y

unsigned char num

inti

if( NumColors!=256){

MessageBox(hWnd,"Must be a mono bitmap with grayscale palette!","Error Message",MB_OK|MB_ICONEXCLAMATION)

return FALSE

}

BufSize=bf.bfSize-sizeof(BITMAPFILEHEADER)

if((hTempImgData=LocalAlloc(LHND,BufSize))==NULL)

{

MessageBox(hWnd,"Error alloc memory!","Error Message",MB_OK|MB_ICONEXCLAMATION)

return FALSE

}

lpImgData=(LPBITMAPINFOHEADER)GlobalLock(hImgData)

lpTempImgData=(LPBITMAPINFOHEADER)LocalLock(hTempImgData)

//copy image data

memcpy(lpTempImgData,lpImgData,BufSize)

if(Hori)

{

for(y=0y<bi.biHeighty++){

lpPtr=(char *)lpImgData+(BufSize-LineBytes-y*LineBytes)+1

lpTempPtr=(char *)lpTempImgData+(BufSize-LineBytes-y*LineBytes)+1

for(x=1x<bi.biWidth-1x++){

num=(unsigned char)*lpPtr

if (num==0){

*lpTempPtr=(unsigned char)0

for(i=0i<3i++){

num=(unsigned char)*(lpPtr+i-1)

if(num==255){

*lpTempPtr=(unsigned char)255

break

}

}

}

else *lpTempPtr=(unsigned char)255

lpPtr++

lpTempPtr++

}

}

}

else{

for(y=1y<bi.biHeight-1y++){

lpPtr=(char *)lpImgData+(BufSize-LineBytes-y*LineBytes)

lpTempPtr=(char *)lpTempImgData+(BufSize-LineBytes-y*LineBytes)

for(x=0x<bi.biWidthx++){

num=(unsigned char)*lpPtr

if (num==0){

*lpTempPtr=(unsigned char)0

for(i=0i<3i++){

num=(unsigned char)*(lpPtr+(i-1)*LineBytes)

if(num==255){

*lpTempPtr=(unsigned char)255

break

}

}

}

else *lpTempPtr=(unsigned char)255

lpPtr++

lpTempPtr++

}

}

}

if(hBitmap!=NULL)

DeleteObject(hBitmap)

hDc=GetDC(hWnd)

hBitmap=CreateDIBitmap(hDc, (LPBITMAPINFOHEADER)lpTempImgData, (LONG)CBM_INIT,

(LPSTR)lpTempImgData+sizeof(BITMAPINFOHEADER) +NumColors*sizeof(RGBQUAD),

(LPBITMAPINFO)lpTempImgData, DIB_RGB_COLORS)

if(Hori)

hf=_lcreat("c:\\herosion.bmp",0)

else

hf=_lcreat("c:\\verosion.bmp",0)

_lwrite(hf,(LPSTR)&bf,sizeof(BITMAPFILEHEADER))

_lwrite(hf,(LPSTR)lpTempImgData,BufSize)

_lclose(hf)

ReleaseDC(hWnd,hDc)

LocalUnlock(hTempImgData)

LocalFree(hTempImgData)

GlobalUnlock(hImgData)

return TRUE

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7788623.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存