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

📄 linjunjuanview.cpp

📁 图像处理软件,功能比较基础
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			CPen* pOldPen=currentDC->SelectObject(&newPen);
			currentDC->SetROP2(R2_NOT);		
			currentDC->SelectObject(GetStockObject(HOLLOW_BRUSH));
			currentDC->Ellipse(ptEllipseBeg1.x,ptEllipseBeg1.y,ptEllipseEnd1.x,ptEllipseEnd1.y);
			currentDC->Ellipse(ptEllipseBeg2.x,ptEllipseBeg2.y,ptEllipseEnd2.x,ptEllipseEnd2.y);
			currentDC->SelectObject(pOldPen);
			CLinjunjuanView::ReleaseDC(currentDC);					
		}
	}
	
	if(fBlocking)
	{
		SetCursor(LoadCursor(NULL,IDC_CROSS));
		DrawBoxOutLine(ptBeg,ptEnd);
		ptEnd.x=point.x;
		ptEnd.y=point.y;
		{
			if(m_pDlgexit==FALSE)
			{
				char *buffer;
				buffer= new char [7];
				_itoa(ptBeg.x+GetScrollPos(SB_HORZ),buffer,10);
				m_pDlg->m_block_x=buffer;
				_itoa(ptBeg.y+GetScrollPos(SB_VERT),buffer,10);
				m_pDlg->m_block_y=buffer;
				_itoa(abs(ptEnd.x-ptBeg.x),buffer,10);
				m_pDlg->m_block_length=buffer;
				_itoa(abs(ptEnd.y-ptBeg.y),buffer,10);				
				m_pDlg->m_block_width=buffer;
				delete []buffer;
			}
			
			
		}
		DrawBoxOutLine(ptBeg,ptEnd);//?		
	}
	if (m_pDlgexit==FALSE)
	{
		nowpos.x=point.x+GetScrollPos(SB_HORZ);
		nowpos.y=point.y+GetScrollPos(SB_VERT);

		
		SetTimer (1, 10, NULL);
	}

	CScrollView::OnMouseMove(nFlags, point);
}

void CLinjunjuanView::OnCopy() 
{
	POINT tempBeg,tempEnd;
	tempBeg.x=ptBeg.x+GetScrollPos(SB_HORZ);
	tempBeg.y=ptBeg.y+GetScrollPos(SB_VERT);
	tempEnd.x=ptEnd.x+GetScrollPos(SB_HORZ);
	tempEnd.y=ptEnd.y+GetScrollPos(SB_VERT);
	if(fValidBox)
	{
		CLinjunjuanDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		theApp.clipboard.CopyToClipbox(pDoc->orgpic,tempBeg,tempEnd);
	}	
	
}

void CLinjunjuanView::OnPaste() 
{
	CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// Get the active MDI child window.
	CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
// or CMDIChildWnd *pChild = pFrame->MDIGetActive();

// Get the active view attached to the active MDI child
// window.
	CLinjunjuanView *pView = (CLinjunjuanView *) pChild->GetActiveView();
	CLinjunjuanDoc* pDoc =pView->GetDocument();
	ASSERT_VALID(pDoc);
	if(pDoc->flagpic==FALSE)
	{
		pDoc->orgpic=theApp.clipboard.CopyToTemplate();
		if(pDoc->orgpic.p==NULL)
		{
			AfxMessageBox("拷贝错误!");
			return;
		}
		pDoc->SaveHistory();
		if ((pDoc->m_hDIB=ChangeToHDIB(pDoc->orgpic))==NULL)
			return ;
		pDoc->InitDIBData();
		pDoc->flagpic=TRUE;
		theApp.m_Pot+=CSize(20,20);
		pDoc->UpdateAllViews(NULL);
	}
}

void CLinjunjuanView::OnCheckclip() 
{
	theApp.clipboard.DoModal();	
}

void CLinjunjuanView::OnImageSelectrect() 
{
	if(rectSelect==TRUE)
	{
		rectSelect=FALSE;
		fBlocking=FALSE;
		fValidBox=FALSE;			
		m_pDlg->m_block_x="";		
		m_pDlg->m_block_y="";		
		m_pDlg->m_block_length="";		
		m_pDlg->m_block_width="";
		Invalidate(FALSE);
	}
	else
	rectSelect=TRUE;	
}

void CLinjunjuanView::OnUpdateImageSelectrect(CCmdUI* pCmdUI) 
{
	if(rectSelect==TRUE)
		pCmdUI->SetCheck(1);
	else
		pCmdUI->SetCheck(0);
	
}

void CLinjunjuanView::OnImageReverse() 
{
	CLinjunjuanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	for(int i=0;i<pDoc->orgpic.row;i++)
		for (int j=0;j<pDoc->orgpic.col;j++)
			pDoc->orgpic.p[i][j]=255-pDoc->orgpic.p[i][j];
	if ((pDoc->m_hDIB=ChangeToHDIB(pDoc->orgpic))==NULL)
	{
		AfxMessageBox("不能显示!");
		return ;
	}
	pDoc->SaveHistory();
	pDoc->InitDIBData();
	pDoc->UpdateAllViews(NULL);
	
	
}

void CLinjunjuanView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{	
	up=GetScrollPos(SB_VERT);
	CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CLinjunjuanView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	left=GetScrollPos(SB_HORZ);
	CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CLinjunjuanView::OnUpdateCopy(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(fValidBox);	
}

void CLinjunjuanView::OnSeePixel() 
{
	if (m_pDlg->GetSafeHwnd()==0)
	{
		m_pDlg->Create();
	}

	CLinjunjuanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
   int  decimal, sign;
   CString buffer;
   

    buffer = _fcvt( pDoc->m_aver,1,&decimal,&sign);
	buffer.Insert(decimal,'.');
	m_pDlg->m_average=buffer;
	m_pDlg->SetWindowText(pDoc->GetTitle( ));
    
	
	
	m_pDlg->gray=HistoGarm (pDoc->orgpic);
	m_pDlg->flagHis=TRUE;
	
	

	m_pDlg->ShowWindow(SW_SHOW);
	m_pDlgexit=FALSE;
}

void CLinjunjuanView::OnTimer(UINT nIDEvent) 
{
	char *buffer;
	buffer= new char [5];	
	
	CLinjunjuanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (nowpos.y<pDoc->orgpic.row&&nowpos.x<pDoc->orgpic.col)
	{	
		_itoa((int)pDoc->orgpic.p[nowpos.y][nowpos.x],buffer,10);				
		m_pDlg->m_pixel1=buffer;
		_itoa(nowpos.x,buffer,10);
		m_pDlg->m_row=buffer;
		_itoa(nowpos.y,buffer,10);
		m_pDlg->m_col=buffer;
		m_pDlg->UpdateData(FALSE);
	}
	delete buffer;
	KillTimer(1);
	CScrollView::OnTimer(nIDEvent);
}

void CLinjunjuanView::OnDig1000() 
{
	if (fCircling)
	{	
		fCircling=FALSE;
		fShowCircling=FALSE;
		Invalidate(FALSE);
	}
	else
	{
		fCircling=TRUE;
		fShowCircling=FALSE;
		CUT_PARAMETER dlg;
		if(dlg.DoModal()==IDOK)
		{
			outer_circle=(int)((dlg.m_height*tan(34*PI/180.0))/10);
			inner_circle=(int)((dlg.m_height*tan(10*PI/180.0))/10);
			height=dlg.m_height;
		}	
		Invalidate(FALSE);	
	}
	
}
BOOL CLinjunjuanView::WriteWindowPicToFile(LPTSTR szFile, CWnd* pWnd)
{
	CWzdBitmap bitmap;
	CWindowDC	dc(pWnd);
	CDC 		memdc;
	CRect		rect;
	::UpdateWindow(pWnd->GetSafeHwnd ());
	memdc.CreateCompatibleDC(&dc); 

	pWnd->GetClientRect(&rect);

	int Width=rect.Width() ;
	int Height=rect.Height() ;
	bitmap.CreateCompatibleBitmap(&dc, Width , Height );
	
	CBitmap* poldbitmap = memdc.SelectObject(&bitmap);
	memdc.BitBlt(0, 0, Width ,Height , &dc, rect.left , rect.top,SRCCOPY); 

	// create logical palette if device support a palette
	CPalette pal;
	if( dc.GetDeviceCaps (RASTERCAPS) & RC_PALETTE )
	{
		UINT nsize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
		LOGPALETTE *plp = (LOGPALETTE *) new BYTE[nsize];
		plp->palVersion = 0x300;

		plp->palNumEntries = GetSystemPaletteEntries( dc, 0, 255, plp->palPalEntry );

		// create the palette
		pal.CreatePalette( plp );

		delete[] plp;
	}	
	memdc.SelectObject(poldbitmap);
	bitmap.SaveBitmapEx(szFile);
	return TRUE;

}


void CLinjunjuanView::OnUpdateSeePixel(CCmdUI* pCmdUI) 
{
	if(m_pDlgexit==FALSE)
		pCmdUI->Enable(FALSE);
	else
		pCmdUI->Enable(TRUE);
}

void CLinjunjuanView::OnDrawLine() 
{	
  /*  currentDC=CLinjunjuanView::GetDC();	
	POINT end1,beg1;
	beg1.x=0;beg1.y=0;
	end1.x=100;end1.y=100;
	currentDC->MoveTo(beg1);
	currentDC->LineTo(end1);	
	CDC memDC;
	memDC.CreateCompatibleDC(currentDC);
	CBitmap bitmap;
	memDC.SelectObject(&bitmap);
	memDC.BitBlt(0,0,350,350,currentDC,0,0,SRCCOPY);
	


//	unsigned char lpbit[350][350];
//	GetObject(HBITMAP,350*350,lpbit);
//	hBitmap = (HBITMAP)::SelectObject(memDC,hBitmapOld);

int nXDest, 
int nYDest, 
int nWidth, 
int nHeight, 
HDC hdcSrc, 
int nXSrc, 
int nYSrc, 
DWORD dwRop );	
	//CBitmap *bitmap=memDC.GetCurrentBitmap( );
	CSize size=bitmap.GetBitmapDimension();
	SaveDIBFile(HDIB hDib, "c:\\lllp.raw");
	unsigned char lpbit[350*350];
	bitmap.GetBitmapBits(350*350,lpbit);
	BITMAP map;
	bitmap.GetBitmap(&map);
	//map.bmBits
	FILE *fp;
	fp=fopen("c:\\lllp.raw","wb");
	fwrite(map.bmBits,350*350,1,fp);
	fclose(fp);
	CLinjunjuanView::ReleaseDC(currentDC);	*/
}

void CLinjunjuanView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	
	if(drawmark==TRUE)
	{
		drawmark=FALSE;
		Invalidate(FALSE);
	}		
	if(fCircling)
	{		
		POINT Client_circle;			

		char filename[512];
		char txtname[512];
		GetCurrentDirectory(512,filename);
		GetCurrentDirectory(512,txtname);
		if(height==10000)
		{
			strcat(filename,"\\tgOrgSAR10k001.pic");
			strcat(txtname,"\\tgdPos10k.txt");
		}
		else if(height==8000)
		{
			strcat(filename,"\\tgOrgSAR08k001.pic");
			strcat(txtname,"\\tgPos08k.txt");
		}
		else if(height==6000)
		{
			strcat(filename,"\\tgPos06k001.pic");
			strcat(txtname,"\\tgPos06k.txt");
		}
		else if(height==4000)
		{
			strcat(filename,"\\tgOrgSAR04k001.pic");
			strcat(txtname,"\\tgPos04k.txt");
		}		
	
		FILE *fp;
	/*		fp=fopen(txtname,"w");
		fprintf(fp,"                    原始截取模拟SAR图\n");
		fprintf(fp,"高度为%dm\n\n",height);
		fclose(fp);	
*/
		int x,y;
		Picture temp;
		temp.p=fspace_2d(1500,1500);
		temp.row=temp.col=1500;
		CLinjunjuanDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

		for (int m=0;m<25;m++)
		{
			x=rand()%700;
			y=rand()%100;
			Client_circle.x=1400+x;
			Client_circle.y=1600+y;		
			for (int i=0;i<1500;i++)
				for (int j=0;j<1500;j++)
				{
					temp.p[i][j]=pDoc->orgpic.p[i-1500/2+Client_circle.y][j-1500/2+Client_circle.x];
				}
				::writepic(filename,temp);				
				fp=fopen(txtname,"a");
				fprintf(fp,"截图点(中心点)row  =  %d  ,  截图点(中心点)col  =  %d,   图片号码= % d,\n",Client_circle.y,Client_circle.x,m+1);
				fclose(fp);				
				ChangeNameExtension1(filename);
		}
		
		/*
	POINT Client_circle;
	Client_circle.x=point.x+left;
	Client_circle.y=point.y+up;
	int row,col;
	Picture outpic;
	CLinjunjuanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	row=pDoc->orgpic.row;
	col=pDoc->orgpic.col;
	int outrectlength=0;
	if(outer_circle>500)
	outrectlength=1500;
	else
	outrectlength=1500;			
	outpic.row=outrectlength;
	outpic.col=outrectlength;
	if(Client_circle.x<outer_circle)
	{
	::MessageBox(NULL,"选择区域太小,太靠左边","Error",MB_OK);
	return;
	}
	if(Client_circle.y<outer_circle)
	{
	::MessageBox(NULL,"选择区域太小,太靠上边","Error",MB_OK);
	return;
	}
	
	  if(Client_circle.x+outrectlength>col)
	  {
	  ::MessageBox(NULL,"选择区域太小,太靠右边","Error",MB_OK);
	  return;
	  }
	  if(Client_circle.y+outrectlength>row)
	  {
	  ::MessageBox(NULL,"选择区域太小,太靠下边","Error",MB_OK);
	  return;
	  }		
	  fCircling=FALSE;
	  ptEllipseBeg1.x=point.x+left-inner_circle;
	  ptEllipseBeg1.y=point.y+up-inner_circle;
	  ptEllipseEnd1.x=point.x+left+inner_circle;
	  ptEllipseEnd1.y=point.y+up+inner_circle;
	  ptEllipseBeg2.x=point.x+left-outer_circle;
	  ptEllipseBeg2.y=point.y+up-outer_circle;
	  ptEllipseEnd2.x=point.x+left+outer_circle;
	  ptEllipseEnd2.y=point.y+up+outer_circle;
	  fShowCircling=TRUE;
	  Invalidate(FALSE);			
	  outpic.p=fspace_2d(outrectlength,outrectlength);
	  if (outpic.p==NULL)
	  {
	  ::MessageBox(NULL,"分配错误","Error",MB_OK);
	  return;
	  }
	  for (int i=0;i<outrectlength;i++)
	  for (int j=0;j<outrectlength;j++)
	  {
	  if((i-outrectlength/2+Client_circle.y<row)&&(i-outrectlength/2+Client_circle.y>=0)&&(j-outrectlength/2+Client_circle.x<col)&&(j-outrectlength/2+Client_circle.x>=0))
	  outpic.p[i][j]=pDoc->orgpic.p[i-outrectlength/2+Client_circle.y][j-outrectlength/2+Client_circle.x];
	  else
	  outpic.p[i][j]=0;
	  }
	  ::MessageBox(NULL,"挖图","通知",MB_OK);
	  char ext[] = "picture types (*.bmp)|*.bmp|picture types (*.pic)|*.pic||";
	  CFileDialog dlg(FALSE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);			
	  if(dlg.DoModal() == IDOK)
	  {		
	  ::writepic(dlg.GetPathName(),outpic);		
	  dspace_2d(outpic.p,outrectlength,outrectlength);
	  ::MessageBox(NULL,"挖图信息文本","通知",MB_OK);
	  char ext1[] = "picture types (*.txt)|*.txt||";
	  CFileDialog dlgtxt(FALSE,"txt" ,"*.txt",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext1, NULL);				
	  {
	  if(dlgtxt.DoModal() == IDOK)
	  {
						FILE *fp;
						fp=fopen(dlgtxt.GetPathName(),"w");
						fprintf(fp," row  =  %d  , col  =  %d",Client_circle.y,Client_circle.x);
						fclose(fp);
						}
						}	
						::MessageBox(NULL,"参考","通知",MB_OK);
						CFileDialog dlgshow(FALSE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);
						if(dlgshow.DoModal() == IDOK)
						{
						WriteWindowPicToFile((dlgshow.GetPathName()).GetBuffer((dlgshow.GetPathName()).GetLength()),GetFocus());						
				}				
	}
	
	else 
	{
		dspace_2d(outpic.p,outrectlength,outrectlength);
		return ;
	}			*/
	}	
	CScrollView::OnLButtonDblClk(nFlags, point);
}

void CLinjunjuanView::OnUpdateDig1000(CCmdUI* pCmdUI) 
{
	if (fCircling)
	{
		pCmdUI->SetCheck(1);
	}
	else
	{
		pCmdUI->SetCheck(0);
	}	
}

void CLinjunjuanView::OnProduceMask() 
{
	Picture pic;	
	CLinjunjuanDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	/*
	pic.row=pDoc->orgpic.row;
	pic.col=pDoc->orgpic.col;
	pic.p=fspace_2d(pic.row,pic.col);
	for(int i=0;i<pic.row;i++)
		for (int j=0;j<pic.col;j++)
			pic.p[i][j]=255;
		int Maskinner=37*37,Maskouter=165*165;
		int span;
		for (i=0;i<pic.row;i++)
			for (int j=0;j<pic.col;j++)
			{
				span=(int)(pow(i-pic.row/2,2)+pow(j-pic.col/2,2));
				if(span<=Maskinner||span>Maskouter)
					pic.p[i][j]=0;
			}
			*/
	pic.row=330;
	pic.col=330;
	pic.p=fspace_2d(pic.row,pic.col);
		for (int i=0;i<pic.row;i++)
			for (int j=0;j<pic.col;j++)
			{
				pic.p[i][j]=pDoc->orgpic.p[i+10][j+10];
			}	
			char ext[] = "picture types (*.bmp)|*.bmp|picture types (*.pic)|*.pic||";
			CFileDialog dlg(FALSE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);			
			if(dlg.DoModal() == IDOK)
			{
				::writepic(dlg.GetPathName(),pic);		
			}
			
}

void CLinjunjuanView::OnAirDraw() 
{
	
	CDrawRectangle drawDlg;
	if(drawDlg.DoModal()==IDOK)
	{
		markfirst1.x=drawDlg.m_real_x;
		markfirst1.y=drawDlg.m_real_y;
		markfirst2.x=drawDlg.m_old_x;
		markfirst2.y=drawDlg.m_old_y;
		markfirst3.x=drawDlg.m_new_x;
		markfirst3.y=drawDlg.m_new_y;
		drawmark=TRUE;
		Invalidate(FALSE);		
		char ext[] = "picture types (*.bmp)|*.bmp|picture types (*.pic)|*.pic||";
		CFileDialog dlg(FALSE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);			
		if(dlg.DoModal()==IDOK)
		{
			WriteWindowPicToFile((dlg.GetPathName()).GetBuffer((dlg.GetPathName()).GetLength()),GetFocus());
		}
	}
}

void CLinjunjuanView::OnAllDraw() 
{	
	
	markfirst_all.x=109,markfirst_all.y=223;
	drawmark_all=TRUE;
	Invalidate(FALSE);		
	char ext[] = "picture types (*.bmp)|*.bmp|picture types (*.pic)|*.pic||";
	CFileDialog dlg(FALSE,"bmp" ,"*.bmp",OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY ,ext, NULL);			
	if(dlg.DoModal()==IDOK)
	{
		WriteWindowPicToFile((dlg.GetPathName()).GetBuffer((dlg.GetPathName()).GetLength()),GetFocus());
	}
	
}
                  

⌨️ 快捷键说明

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