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

📄 settings.cpp

📁 又VC++实现的基于TWAIN的扫描仪图像输入处理软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:

  if(m_sUnit=="厘米")
  {
      m_nX0=m_nZeroX/2.54;
      m_nY0=m_nZeroY/2.54;

      if((m_nWidth+m_nX0)>(shuzu3/FuMian*10.0*2.54))
	  {
        m_nWidth=shuzu3/FuMian*10.0*2.54-m_nX0;
	  }
      m_nWidth0=m_nWidth/2.54;
	  if((m_nLength+m_nY0)>(shuzu5/FuMian*10.0*2.54))
	  {
        m_nLength=shuzu5/FuMian*10.0*2.54-m_nY0;
	  }
      m_nLength0=m_nLength/2.54;
  } 

    //保证偶数点开始扫描
	r.left=(long)(m_nX0*FuMian);
	r.top=(long)(m_nY0*FuMian);
	r.right=(long)((m_nX0+m_nWidth0)*FuMian);
	r.bottom=(long)((m_nY0+m_nLength0)*FuMian);

    if(m_sUnit=="英寸")
	{
	    m_nZeroX=(double)((int)(r.left/FuMian*100)/100.0);
	    m_nZeroY=(double)((int)(r.top/FuMian*100)/100.0);
        m_nWidth=(double)((int)((r.right-r.left)/FuMian*100)/100.0);
	    m_nLength=(double)((int)((r.bottom-r.top)/FuMian*100)/100.0);
	    //m_nSizeImage=m_nWidth*m_nLength*(pScanner->m_nDPI)*(pScanner->m_nDPI)*3/1024;
	}
   
    sprintf(str, "%d", r.left/10.0);
	WritePrivateProfileString("select", "left", str, InitDir2);
	sprintf(str, "%d", r.right/10.0);
    WritePrivateProfileString("select", "right", str, InitDir2);
	sprintf(str, "%d", r.top/10.0);
	WritePrivateProfileString("select", "top", str, InitDir2);
	sprintf(str, "%d",r.bottom/10.0 );
    WritePrivateProfileString("select", "bottom", str, InitDir2);
   
    switch(pScanner->m_nColor)
	{
	  case  16777216:
		m_nSizeImage=m_nWidth0*m_nLength0*(pScanner->m_nDPI)*(pScanner->m_nDPI)*3/1024;
		break;
	  case 256:
		m_nSizeImage=m_nWidth0*m_nLength0*(pScanner->m_nDPI)*(pScanner->m_nDPI)/1024;
		break;
	  case 2:
		m_nSizeImage=m_nWidth0*m_nLength0*(pScanner->m_nDPI)*(pScanner->m_nDPI)/8/1024;
		break;
	}
	m_nSizeImage = (int)(m_nSizeImage/1024*100)/100.0;
	pViewWnd->m_iCursorType=CT_CROSS;
    pScanner->SetSelectZoom(r);
	pViewWnd->DrawRect(r);
    m_pPositionInfo->SetPosition(r,0);

	UpdateData(false);  	
   ((CSetScanner*)m_pParent)->BoxDone(IDC_SHOW_SETTINGS);
    CDialog::OnOK();
}

//////////////////////////////////////////////////////////////////
//检查单选框,用来确定是图像增强方式                                                   //
//////////////////////////////////////////////////////////////////	
void CSettings::OnCheck1() 
{
	
	/*int ImgEnha=GetPrivateProfileInt("Image_Enah","Enah_Enable",0,InitDir2);
	if (ImgEnha==0)
	{
			zengqiang=false;
	}
	else
	{
			zengqiang=true;
	}*/
	

	zengqiang=!zengqiang;

   if(zengqiang==TRUE)
   {
     ::EnableWindow(::GetDlgItem(this->m_hWnd,IDC_BC),TRUE);
	 pScanner->quesheng=FALSE;
     //MessageBox("增强"," 增强",MB_OK);
	//按照上次增强参数修正预览图像
     jiaose1();
	 //ImgEnha=1;	
   }
   else
   {
       //MessageBox("缺省"," 缺省",MB_OK); 
     ::EnableWindow(::GetDlgItem(this->m_hWnd,IDC_BC),FALSE);
	  pScanner->quesheng=TRUE;
	 //按照缺省参数修正预览图像显示
     char IniFile[120];
     GetWindowsDirectory(IniFile,sizeof(IniFile));
     char* pFileName=lstrcat(IniFile,"\\twain_32\\MTIScanner\\preview.bmp");  
     HDIB hbmp;
   	 
	 hbmp=::ReadDIBFile( pFileName );
	 pScanner->SetHandleofPreviewBMP(hbmp);
	 hbmp=::ReadDIBFile( pFileName );
	 pScanner->SetHandleofAdjustedPreviewBMP(hbmp);
	 HANDLE hDIB0 = pScanner->GetHandleofPreviewBMP();
	 HANDLE hDIB1 = pScanner->GetHandleofAdjustedPreviewBMP();

//	 ImgEnha=0;	
   }

	char	str[5];
	sprintf(str, "%d", int(zengqiang));
	WritePrivateProfileString("Image_Enah","Enah_Enable",str,InitDir2);

	pViewWnd->InvalidateRect(NULL);

   	RECT tempRect;

    tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
    tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
    tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
    tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;

	UpdateData(TRUE) ;

  	m_pPositionInfo->SetPosition(tempRect,0);

	UpdateData(FALSE);
}

/////////////////////////////////////////////////////////////////
//				选择扫描校正方式
/////////////////////////////////////////////////////////////////
void CSettings::OnSelchangeComboJZMode() 
{
   UpdateData(true);
   SetJZmode(m_sJZMode);
}

/////////////////////////////////////////////////////////////////
//选择扫描图像的方式,即TWAIN方式还是文件扫描方式
/////////////////////////////////////////////////////////////////
void CSettings::OnSelchangeComboSaomiao() 
{
   int n;
   UpdateData(true);
   if(m_sScanType=="Twain扫描")
   {
      n=0;
   }
   if(m_sScanType=="文件扫描")
   {
      n=1;
   } 
   SetScanWay(n);
}

/////////////////////////////////////////////////////////////////
//选择扫描回归方式
/////////////////////////////////////////////////////////////////
void CSettings::OnSelchangeComboHuigui() 
{
   int n;
   UpdateData(true);
   if(m_sHuiGuiType=="零点位置")
   {
      n=0;
   }
   if(m_sHuiGuiType=="静止不动")
   {
      n=1;
   } 
   if(m_sHuiGuiType=="中间位置")
   {
      n=2;
   } 
   SetHuiGuiWay(n);
}
/////////////////////////////////////////////////////////////
//通道选择,即扫描黑白灰度图像时的线阵选择
/////////////////////////////////////////////////////////////
void CSettings::OnSelchangeComboChannel() 
{
    UpdateData(true);

   if(m_sChannel=="红色通道")
      SetChannel(44);
   else if(m_sChannel=="绿色通道")
	  SetChannel(42);
   else if(m_sChannel=="蓝色通道")
	 SetChannel(41);
} 

/*
///////////////////////////////////////////////////////////
//调用感光寄存器修正窗口
///////////////////////////////////////////////////////////
void CSettings::OnGanguang() 
{
   m_pGanWindow = new CJiaoZheng(this);
   m_pGanWindow->Create();
}

*/
////////////////////////////////////////////////////////////////////
//改变设置单位                                                     //
////////////////////////////////////////////////////////////////////
void CSettings::OnSelchangeComboUnit() 
{   
	RECT tempRect;

    tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
    tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
    tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
    tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;

	UpdateData(TRUE) ;

    m_nX0=(double)((int)(pViewWnd->m_SelectZoom.left*10/FuMian*100)/100.0);
    m_nY0=(double)((int)(pViewWnd->m_SelectZoom.top*10/FuMian*100)/100.0);
	m_nWidth0=(double)((int)((pViewWnd->m_SelectZoom.right-pViewWnd->m_SelectZoom.left)*10/FuMian*100)/100.0);
	m_nLength0=(double)((int)((pViewWnd->m_SelectZoom.bottom-pViewWnd->m_SelectZoom.top)*10/FuMian*100)/100.0);
   
   	if(m_sUnit=="英寸")
	{
	  m_nZeroX=m_nX0;
      m_nZeroY= m_nY0;
	  m_nWidth=m_nWidth0;
	  m_nLength=m_nLength0;
	}
	if(m_sUnit=="厘米")
	{
      m_nZeroX=(double)((int)(pViewWnd->m_SelectZoom.left*10/FuMian*2.54*100)/100.0);;
      m_nZeroY=(double)((int)(pViewWnd->m_SelectZoom.top*10/FuMian*2.54*100)/100.0);
	  m_nWidth=(double)((int)((pViewWnd->m_SelectZoom.right-pViewWnd->m_SelectZoom.left)*10/FuMian*2.54*100)/100.0);
	  m_nLength=(double)((int)((pViewWnd->m_SelectZoom.bottom-pViewWnd->m_SelectZoom.top)*10/FuMian*2.54*100)/100.0);
	}

    WritePrivateProfileString("scan unit", "unit", m_sUnit, InitDir2); 
  	m_pPositionInfo->SetPosition(tempRect,0);
	UpdateData(FALSE);
}
///////////////////////////////////////////////////////////
//设置文件类型,被主菜单和设置窗口调用                    //
///////////////////////////////////////////////////////////
void CSettings::SetFileType(int nType)
{
    char str[36];
	int n;
    int i;
	int nTemp;
  
    HDIB hbmp;
    RECT tempRect;
    CRect rect;

	tempRect.top	= (pViewWnd->m_SelectZoom.top)*10;
	tempRect.left	= (pViewWnd->m_SelectZoom.left)*10;
 	tempRect.right	= (pViewWnd->m_SelectZoom.right)*10;
	tempRect.bottom = (pViewWnd->m_SelectZoom.bottom)*10;

//**********************************************************************
//以下代码是根据不同图像类型,在预览区域显示图像                       //
//**********************************************************************
    char IniFile[120];
    GetWindowsDirectory(IniFile,sizeof(IniFile));
	char* pFileName=lstrcat(IniFile,"\\twain_32\\MTIScanner\\preview.bmp"); 

   	hbmp=::ReadDIBFile( pFileName );
    if(hbmp==NULL)
    {
		MessageBox("不存在预览图像文件,重新预览图像","出错",MB_OK);
		return;
	}
	pScanner->SetHandleofAdjustedPreviewBMP(hbmp);
	HANDLE hDIB1=pScanner->GetHandleofAdjustedPreviewBMP();
    HANDLE hDIB0=pScanner->GetHandleofPreviewBMP();
    	    
	LPSTR    lpDIBHdr;
    LPSTR    lpDIBHdr1;
	LPSTR    lpDIB1Bits;
	LPSTR    lpDIB0Bits;          
	LPSTR    lpd0,lpd1;
	
	lpDIBHdr   = (LPSTR) ::GlobalLock((HGLOBAL) hDIB0);
	lpDIB0Bits = ::FindDIBBits(lpDIBHdr);
    lpDIBHdr1  = (LPSTR) ::GlobalLock((HGLOBAL) hDIB1);
	lpDIB1Bits = ::FindDIBBits(lpDIBHdr1);
    lpd0=lpDIB0Bits;
	lpd1=lpDIB1Bits;
	
	int cxDIB = (int) ::DIBWidth(lpDIBHdr);        
	int cyDIB = (int) ::DIBHeight(lpDIBHdr);      
	int colornum=(int)::DIBNumColors(lpDIBHdr);
	int nBitCount;

    if(colornum==2)
	 {
    	nBitCount=cxDIB*cyDIB/8;
	 }
    else if(colornum==256)
	 {
       nBitCount=cxDIB*cyDIB;
	 }
    else
	 {
       nBitCount=cxDIB*cyDIB*3;
	 }

    //根据不同图像类型选择,确定预览图像数据
    if(colornum==0) //预览图像本身是彩色图像,可以显示为灰度和黑白图像
    {
       if(nType==16777216)
	   {
         pScanner->m_nh=FALSE;  
         for(i=0;i<nBitCount;i++)
		 {
           *(unsigned char*)(lpDIB0Bits)=*(unsigned char*)(lpDIB1Bits);
           (unsigned char*)lpDIB0Bits++;  
           (unsigned char*)lpDIB1Bits++;
           *(unsigned char*)(lpDIB0Bits)=*(unsigned char*)(lpDIB1Bits);
           (unsigned char*)lpDIB0Bits++;  
           (unsigned char*)lpDIB1Bits++;
           *(unsigned char*)(lpDIB0Bits)=*(unsigned char*)(lpDIB1Bits);
           (unsigned char*)lpDIB0Bits++;  
           (unsigned char*)lpDIB1Bits++;
		   i++;
		   i++;
		 }
	   }
	   if(nType==256)
	   {
   	      pScanner->m_nh=FALSE; 	
		  for(i=0;i<nBitCount;i++)
		  {
		    nTemp=(int)(*(unsigned char*)(lpDIB1Bits)*0.2+*(unsigned char*)(lpDIB1Bits+1)*0.21+*(unsigned char*)(lpDIB1Bits+2)*0.59);
		    *(unsigned char*)(lpDIB0Bits)=nTemp;
             (unsigned char*)lpDIB0Bits++;
            *(unsigned char*)(lpDIB0Bits)=nTemp;
             (unsigned char*)lpDIB0Bits++;
            *(unsigned char*)(lpDIB0Bits)=nTemp;
		     (unsigned char*)lpDIB0Bits++;

		     (unsigned char*)lpDIB1Bits++;
			 (unsigned char*)lpDIB1Bits++;
             (unsigned char*)lpDIB1Bits++;
			 i++;
			 i++;
		  }
	   }
       if(nType==2)
	   {
         pScanner->m_nh=TRUE; 
	  }
	}//colornum=0结束
    if(colornum==256)  //预览图像本身为灰度图像,可以显示为黑白图像
	{
       if(nType==16777216) 
	   {
         pScanner->m_nh=FALSE; 
         pScanner->m_nColor=16777216;
	   }
       if(nType==256)
	   {
	     pScanner->m_nColor=256;
       	 pScanner->m_nh=FALSE; 	
		 for(i=0;i<nBitCount;i++)
		 {		
	       *(unsigned char*)(lpDIB0Bits)=*(unsigned char*)(lpDIB1Bits);
		   (unsigned char*)lpDIB0Bits++;
		   (unsigned char*)lpDIB1Bits++;	
         }
	   }
       if(nType==2)
	   {
         pScanner->m_nh=TRUE; 
		 pScanner->m_nColor=2;
       }
	}//结束colornum=256的判断
	if(colornum==2) //如果预览图像为黑白图像,则只能显示为黑白图像
	{
      if(nType==16777216)
	  {
        pScanner->m_nh=FALSE; 
        pScanner->m_nColor=16777216;
	  }
      if(nType==256)
	  {
	    pScanner->m_nColor=256;
       	pScanner->m_nh=FALSE; 	
	  }
       if(nType==2)
	  {
        pScanner->m_nh=TRUE; 
		pScanner->m_nColor=2;
	  }
	}
	//在文件中记忆文件类型,针对下一次使用
    if(nType==16777216)
      n=16777216;
   	else if(nType==256)
	  n=256;
	else if(nType==2)
	  n=2;
	sprintf(str, "%d", n);
	WritePrivateProfileString("color num", "color", str, InitDir2);

⌨️ 快捷键说明

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