⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadbmpfile.cpp

📁 这是个很好的数据库源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
       lpTempImgData=(LPBITMAPINFOHEADER)LocalLock(hTempImgData);

       lpPtr=(char *)lpImgData;

       lpTempPtr=(char *)lpTempImgData;

//先将原图直接拷贝过来,其实主要是拷贝周围一圈的象素

       memcpy(lpTempPtr,lpPtr,BufSize);
///////////////////////////////////////////////////
       for(y=1;y<bi.biHeight-1;y++) //注意y的范围是从1到bi.biHeight-2
		   for(x=1;x<bi.biWidth-1;x++)
		   { //注意x的范围是从1到bi.biWidth-2

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

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


			  TempNum=(float)((unsigned char)*(lpPtr+LineBytes-1))*CoefArray[0];

              TempNum+=(float)((unsigned char)*(lpPtr+LineBytes))*CoefArray[1];

              TempNum+=(float)((unsigned char)*(lpPtr+LineBytes+1))*CoefArray[2];

              TempNum+=(float)((unsigned char)*(lpPtr-1))*CoefArray[3];

              TempNum+=(float)((unsigned char)*lpPtr)*CoefArray[4];

              TempNum+=(float)((unsigned char)*(lpPtr+1))*CoefArray[5];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes-1))*CoefArray[6];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes))*CoefArray[7];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes+1))*CoefArray[8];

                            //最后乘以系数

							TempNum*=coef;

                            //注意对溢出点的处理

                            if(TempNum>255.0) *lpTempPtr=(BYTE)255;

                            else if(TempNum<0.0) 

                                   *lpTempPtr=(unsigned char)fabs(TempNum);

                            else *lpTempPtr=(BYTE)TempNum;
		   }/////////horz
///////////////////////////////vert
	if(Type == 1)
	{	   
		   for(i=0;i<9;i++)
				{
					CoefArray[i] = Template_Horz_Sobel_Vert[i];
				}

	   ////////////////////////////////////////

       for(y=1;y<bi.biHeight-1;y++) //注意y的范围是从1到bi.biHeight-2
		   for(x=1;x<bi.biWidth-1;x++)
		   { //注意x的范围是从1到bi.biWidth-2

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

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


			  TempNum=(float)((unsigned char)*(lpPtr+LineBytes-1))*CoefArray[0];

              TempNum+=(float)((unsigned char)*(lpPtr+LineBytes))*CoefArray[1];

              TempNum+=(float)((unsigned char)*(lpPtr+LineBytes+1))*CoefArray[2];

              TempNum+=(float)((unsigned char)*(lpPtr-1))*CoefArray[3];

              TempNum+=(float)((unsigned char)*lpPtr)*CoefArray[4];

              TempNum+=(float)((unsigned char)*(lpPtr+1))*CoefArray[5];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes-1))*CoefArray[6];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes))*CoefArray[7];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes+1))*CoefArray[8];

                            //最后乘以系数

							TempNum*=coef;

                            //注意对溢出点的处理

               if(TempNum>255.0) *lpTempPtr=(BYTE)255;
			   else
			   {
				   if(TempNum<0.0) 
					   TempNum=fabs(TempNum);
					curColor =*lpTempPtr;
					if((BYTE)TempNum>curColor)
					{
						*lpTempPtr=(BYTE)TempNum;
					}
			   }
		   }/////////vert

		   for(i=0;i<9;i++)
				{
					CoefArray[i] = Template_M1_Sobel[i];
				}

	   ////////////////////////////////////////

       for(y=1;y<bi.biHeight-1;y++) //注意y的范围是从1到bi.biHeight-2
		   for(x=1;x<bi.biWidth-1;x++)
		   { //注意x的范围是从1到bi.biWidth-2

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

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


			  TempNum=(float)((unsigned char)*(lpPtr+LineBytes-1))*CoefArray[0];

              TempNum+=(float)((unsigned char)*(lpPtr+LineBytes))*CoefArray[1];

              TempNum+=(float)((unsigned char)*(lpPtr+LineBytes+1))*CoefArray[2];

              TempNum+=(float)((unsigned char)*(lpPtr-1))*CoefArray[3];

              TempNum+=(float)((unsigned char)*lpPtr)*CoefArray[4];

              TempNum+=(float)((unsigned char)*(lpPtr+1))*CoefArray[5];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes-1))*CoefArray[6];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes))*CoefArray[7];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes+1))*CoefArray[8];

                            //最后乘以系数

							TempNum*=coef;

                            //注意对溢出点的处理

               if(TempNum>255.0) *lpTempPtr=(BYTE)255;
			   else
			   {
				   if(TempNum<0.0) 
					   TempNum=fabs(TempNum);
					curColor =*lpTempPtr;
					if((BYTE)TempNum>curColor)
					{
						*lpTempPtr=(BYTE)TempNum;
					}
			   }
		  }/////////m1
		   for(i=0;i<9;i++)
				{
					CoefArray[i] = Template_M3_Sobel[i];
				}

	   ////////////////////////////////////////

       for(y=1;y<bi.biHeight-1;y++) //注意y的范围是从1到bi.biHeight-2
		   for(x=1;x<bi.biWidth-1;x++)
		   { //注意x的范围是从1到bi.biWidth-2

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

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


			  TempNum=(float)((unsigned char)*(lpPtr+LineBytes-1))*CoefArray[0];

              TempNum+=(float)((unsigned char)*(lpPtr+LineBytes))*CoefArray[1];

              TempNum+=(float)((unsigned char)*(lpPtr+LineBytes+1))*CoefArray[2];

              TempNum+=(float)((unsigned char)*(lpPtr-1))*CoefArray[3];

              TempNum+=(float)((unsigned char)*lpPtr)*CoefArray[4];

              TempNum+=(float)((unsigned char)*(lpPtr+1))*CoefArray[5];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes-1))*CoefArray[6];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes))*CoefArray[7];

              TempNum+=(float)((unsigned char)*(lpPtr-LineBytes+1))*CoefArray[8];

                            //最后乘以系数

							TempNum*=coef;

                            //注意对溢出点的处理

               if(TempNum>255.0) *lpTempPtr=(BYTE)255;
			   else
			   {
				   if(TempNum<0.0) 
					   TempNum=fabs(TempNum);
					curColor =*lpTempPtr;
					if((BYTE)TempNum>curColor)
					{
						*lpTempPtr=(BYTE)TempNum;
					}
			   }
		  }//////M3
	}
///////////////////


hDc=GetDC(hWnd);

     if(hBitmap!=NULL)
           DeleteObject(hBitmap);
if(!(hBitmap=CreateDIBitmap(hDc,(LPBITMAPINFOHEADER)lpTempImgData,(LONG)CBM_INIT,(LPSTR)lpTempImgData+sizeof(BITMAPINFOHEADER)+NumColors*sizeof(RGBQUAD),(LPBITMAPINFO)lpTempImgData,DIB_RGB_COLORS)))
	MessageBox(hWnd,"CreateBitmap Failed!","Warning!",MB_OK);

	memcpy(lpImgData,lpTempImgData,BufSize);

      ReleaseDC(hWnd,hDc);

       LocalUnlock(hTempImgData);

       LocalFree(hTempImgData);

       GlobalUnlock(hImgData);

       return TRUE;

}
point load_bmp_file::FindCenter()
{
       DWORD                 OffBits,BufSize,LineBytes;

	   LPBITMAPINFOHEADER    lpImgData;

       LPSTR                   lpPtr;

       LONG                  x,y;
	   BYTE curColor;

	   point Center;
	   Center.x = Center.y =0;

	   int *NumInLine = new int[bi.biHeight];
	   int *NumInRow  = new int[bi.biWidth];

	   for(x=0;x<bi.biHeight;x++)
		   NumInLine[x] = 0;
	   for(x=0;x<bi.biWidth;x++)
		   NumInRow[x] = 0;

       OffBits=bf.bfOffBits-sizeof(BITMAPFILEHEADER);

	   LineBytes =(DWORD)WIDTHBYTES(bi.biWidth*bi.biBitCount);

       BufSize=OffBits+bi.biHeight*LineBytes;

	   lpImgData=(LPBITMAPINFOHEADER)GlobalLock(hImgData);    
       lpPtr=(char *)lpImgData;
///////////////////////////////////////////////////
       for(y=1;y<bi.biHeight-1;y++) //注意y的范围是从1到bi.biHeight-2
		   for(x=1;x<bi.biWidth-1;x++)
		   { //注意x的范围是从1到bi.biWidth-2
              lpPtr=(char *)lpImgData+(BufSize-LineBytes-y*LineBytes)+x;
			  curColor = *lpPtr;
			  if(curColor<100)
			  {
				  NumInLine[y]++;
				  NumInRow [x]++;
			  }
		   }

	int WindowHeight =10;
	int MaxNum=-1,Pos=0,NumCount=0;
	for(y=WindowHeight/2+1;y<bi.biHeight-WindowHeight/2;y++)
	{
		NumCount = 0;
		for(x=0;x<WindowHeight;x++)
			NumCount += NumInLine[y-WindowHeight/2+x];
		if(NumCount > MaxNum)
		{
			MaxNum = NumCount;
			Pos = y;
		}
	}
	Center.y = Pos;
	MaxNum = -1; Pos = 0;
	for(x=WindowHeight/2;x<bi.biWidth-WindowHeight/2;x++)
	{
		NumCount = 0;
		for(y=0;y<WindowHeight;y++)
			NumCount += NumInRow[x-WindowHeight/2+y];
		if(NumCount >MaxNum)
		{
			MaxNum = NumCount;
			Pos = x;
		}
	}
	Center.x = Pos;

       GlobalUnlock(hImgData);
delete [] NumInLine;
delete [] NumInRow;
       return Center;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -