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

📄 rsimagestarview.cpp

📁 c语言实现的遥感图像处理的一些基本操作
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			  CBrush brush(FillColor);
			  
			  CClientDC dc(this);
			  COLORREF crColor = dc.GetPixel(ppoint);
			  CBrush* pOldBrush = dc.SelectObject(&brush);
		      CPen pen(PS_SOLID, 1, FillColor);
			  
			  ClientToDib(point);
			  CDC * pDibDC = m_pDoc->m_Dib->BeginPaint(&dc);
			  CPen *oldpen=pDibDC->SelectObject(&pen);
			  pOldBrush = pDibDC->SelectObject(&brush);
			  if(m_DrawRect.Width()>1)
			  {
				  CRect rect=m_DibRect;
				 
				  if(m_DrawType==SELECT)
				     pDibDC->FillRect(rect,&brush);
				  else if(m_DrawType==ROUND)
				  {
                       CPoint pos; 
					   pos.x=int(rect.Width()/5.0);
	                   pos.y=int(rect.Height()/5.0);
	                   pDibDC->RoundRect(rect,pos);
				  }
				  else if(m_DrawType==OVAL)
                       pDibDC->Ellipse(rect);
				  else if(m_DrawType==RECT)
				     pDibDC->FillRect(rect,&brush);
				  else if(m_DrawType==CURVE)
				  {
					  if(m_pDoc->pHead!=NULL)
					  {
						  CPoint pos1[200];
						  int i=0;
						  m_pDoc->pTempPt=m_pDoc->pHead;
						  while(m_pDoc->pTempPt!=NULL)
						  {
							  pos1[i]=m_pDoc->pTempPt->point;
							  i++;
							  m_pDoc->pTempPt=m_pDoc->pTempPt->next;
						  }
                          pDibDC->Polygon(&pos1[0],i); 
					  }
				  }
			  }
			  pDibDC->SelectObject(oldpen);
			  pDibDC->SelectObject(pOldBrush);
			  m_pDoc->m_Dib->EndPaint();
		}
		if(m_DrawRect.PtInRect(ppoint))
		 {
			 SetCursor(hCusorMove);
		     m_MoveRgn=true;
		 }
	}
//当拷贝矩形区不为空时,进行矩形区的拖动
    else if(m_ToolOption==SELECT)
	{
		if(m_DrawRect.PtInRect(ppoint))
		{
			flagLB=false;
            m_MoveRgn=true;
		}
		else if (m_hDibEmpty==false)
		{
			SetCursor(m_Cross);
			if(m_pDoc->pHead!=NULL)
			{
				m_pDoc->pTempPt=m_pDoc->pHead;
				while(m_pDoc->pTempPt!=NULL)
				{
					struct Vertex *temp=m_pDoc->pTempPt;
					m_pDoc->pTempPt=m_pDoc->pTempPt->next;
					free(temp);
				}
				m_pDoc->pHead=NULL;
			}
            m_DrawRect=CRect(0,0,0,0);
		    Invalidate(false);
		    m_bDrawRect=true;
			if(time<0)
				time=SetTimer(1,300,NULL);
		    flagLB=false;
		}		

		else if((m_DrawRect.Width()>1)&&(m_hDibEmpty))
		{
			m_pDoc->tempptr=m_pDoc->head;
			while(m_pDoc->tempptr!=NULL)
			{
				if(m_pDoc->tempptr->dib->m_hDIB!=NULL)
				{
                    CreateRgn1(m_pDoc->tempptr);
					m_pDoc->tempptr->dib->PasteToFile(&dc,m_DibRect); 
					GlobalFree(m_pDoc->tempptr->dib->m_hDIB);
					m_pDoc->tempptr->dib->m_hDIB=NULL;
				}
				m_pDoc->tempptr=m_pDoc->tempptr->next;
			}
			m_hDibEmpty=false;
			GlobalFree(m_pDoc->m_Dib->m_hDIB);
			m_pDoc->m_Dib->m_hDIB=NULL;

			m_pDoc->pTempPt=m_pDoc->pHead;
			if(m_pDoc->pTempPt!=NULL)
			{
				while(m_pDoc->pTempPt!=NULL)
				{
					struct Vertex *temp=m_pDoc->pTempPt;
					m_pDoc->pTempPt=m_pDoc->pTempPt->next;
					free(temp);
				}
				m_pDoc->pHead=NULL;
			}				
			m_DrawRect=m_DibRect=CRect(0,0,0,0);
		    m_bDrawRect=true;
			if(time<0)
				time=SetTimer(1,300,NULL);
		    flagLB=false;
			Invalidate(false);
		}
	}

	else if(m_ToolOption==ImageBrowse)
	{
		startpoint=point;
		SetCapture();
	}
//对图象区域以鼠标点为中兴进行缩小
	else if(m_ToolOption==ImageIn)
       OnZoomIn(startpoint,true);

//对图象区域以鼠标点为中兴进行放大
	else if(m_ToolOption==ImageOut)
        OnZoomOut(startpoint,true);
//对图象区域以给定笔宽和背景色进行檫出
	else if(m_ToolOption==ERASE)
	{
		m_bErasing = TRUE;
		SetCapture();

		CClientDC dc(this);
		CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
		pDibDC->SetPixel(startpoint, m_crFillColor);
		m_pDoc->curptr->dib->EndPaint();
//		Invalidate(false);
	}

//对图象区域以给定笔宽和颜色色进行画图
	else if(m_ToolOption==PEN)
	{
		m_bDrawFreeline = TRUE;
		SetCapture();
		
		// set a pixel anyway
		CClientDC dc(this);

		CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
		pDibDC->SetPixel(startpoint, m_crPenColor);
		m_pDoc->curptr->dib->EndPaint();
//		Invalidate(false);
	}

//在图象区域拾取给定点的颜色,宾用它来作为背景或者前景
	else if (m_ToolOption == PICKER)
	{
		CClientDC dc(this);

		COLORREF crColor = dc.GetPixel(point);
		CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
		ASSERT_KINDOF(CMainFrame, pAppFrame);
		if (pAppFrame->m_wndPaintParamBar.m_nSelectColorMode == PP_FILL_COLOR)
		{
			m_crFillColor = crColor;
			ShowFillColor();
		}
		else if (pAppFrame->m_wndPaintParamBar.m_nSelectColorMode == PP_PEN_COLOR)
		{
			m_crPenColor = crColor;
			ShowPenColor();
		}
	}
	else if(m_ToolOption == CURVE)
	{
		SetCursor( m_Cross);
 		if((m_DrawRect.Width()>1)&&(m_pDoc->curptr->dib->m_hDIB!=NULL))
		{
			if(m_pDoc->head!=NULL)
			{
				m_pDoc->tempptr=m_pDoc->head;
				while(m_pDoc->tempptr->dib->m_hDIB!=NULL)
				{
				    CreateRgn1(m_pDoc->tempptr);
					m_pDoc->tempptr->dib->PasteToFile(&dc,m_DibRect); 
					GlobalFree(m_pDoc->tempptr->dib->m_hDIB);
					m_pDoc->tempptr->dib->m_hDIB=NULL;
				}
				m_pDoc->tempptr=m_pDoc->tempptr->next;
			}
			
			GlobalFree(m_pDoc->m_Dib->m_hDIB);
			m_pDoc->m_Dib->m_hDIB=NULL;
		}
		m_DrawRect=CRect(0,0,0,0);
		m_bDrawRect=false;
		m_hDibEmpty=false;
		if(!m_TextCurve)
		{
			m_pDoc->pTempPt=m_pDoc->pHead;
			while(m_pDoc->pTempPt!=NULL)
			{
				struct Vertex *temp=m_pDoc->pTempPt;
				m_pDoc->pTempPt=m_pDoc->pTempPt->next;
				free(temp);
			}
            m_pDoc->pHead=NULL;
			Invalidate(false);
			m_TextCurve=true;
		}

		if(time!=-1)
		{
			KillTimer(time);
			time=-1;
		}

		AddPoint(startpoint);
	}
	else if(m_ToolOption==PAINT)
	{
         FillRgn();
	}
	else if(m_ToolOption==LINE)
	{
		SetCapture();
		SetCursor(m_Cross);
		m_bDrawingRubber=true;
	}
    
	else if(m_ToolOption==RECT)
         InitalDraw();
	else if(m_ToolOption==ROUND)
        InitalDraw();
	else if(m_ToolOption==OVAL)
        InitalDraw();

	else if(m_ToolOption==Text)
	{
		if(!m_TextCurve)
		{
			m_pDoc->pTempPt=m_pDoc->pHead;
			while(m_pDoc->pTempPt!=NULL)
			{
				struct Vertex *temp=m_pDoc->pTempPt;
				m_pDoc->pTempPt=m_pDoc->pTempPt->next;
				free(temp);
			}
			m_pDoc->pHead=NULL;
		}
        if(m_TextCurve)
		{
		    SetCursor( m_Cross);
			AddPoint(startpoint);
		}
		else
		{
			CMyFontDlg fontdlg;
			fontdlg.m_cf.lpLogFont=&logfont;
			fontdlg.m_cf.rgbColors=m_TextColor;
            fontdlg.str=strfont;
			if(fontdlg.DoModal()==IDOK)
			{
		    	m_TextCurve=true;
				strfont=fontdlg.str;
				fontdlg.GetCurrentFont(&logfont);
                m_TextColor=fontdlg.GetColor();
			}
		}
		SetCursor( m_Text);
	}
	else if(m_ToolOption==POLYLINE)
	{
          SetCursor(m_Cross);
		  if(!m_PolyLine)
		  {
		      m_TempPoint=startpoint;
			  m_FirstPoint=startpoint;
              m_PolyLine=true;
		  }
	}
	else if(m_DrawRect.Width()<=1)
	{
		KillTimer(time);
		time=-1;
	}
	else
	   CScrollView::OnLButtonDown(nFlags, point);
}

void CRSImageStarView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    if(m_ToolOption==MOVE)
	{
		CClientDC dc(this);
		OnPrepareDC(&dc);
		CPoint pt = point;
		dc.DPtoLP(&pt);
		if(m_DrawRect.PtInRect(pt))
        	SetCursor(hCusorMove);
		if(m_MoveRgn&&flagLB)
		{
            RgnOffset(point);
			Invalidate(false);
		}
		if((m_pDoc->m_Dib->m_hDIB==NULL)&&(flagLB))
			if(m_DrawRect.Width()<=1)
			{
				AfxMessageBox("没有选中的区域!");
				flagLB=false;
				return;
			}
	}
	else if((m_ToolOption==SELECT)&&m_MoveRgn)
	{
        RgnOffset(point);
		Invalidate(false);
	}
	else if(m_ToolOption==ImageBrowse)
	{
        SetCursor( hHandGrabed);
		if(!flagLB)
			return;
		temppoint=point;
        CPoint total,pos,pos1;
		total=GetTotalSize();
		CRect rect;
		GetClientRect(&rect);
		pos=temppoint-startpoint;
        pos1=GetScrollPosition();
		pos1-=pos;
		if((pos1.x+rect.Width())>total.x)
			pos1.x=total.x-rect.Width();
		if((pos1.y+rect.Height())>total.y)
			pos1.y=total.y-rect.Height();
		startpoint=temppoint;
		ScrollToPosition(pos1);
	}

	else if(m_ToolOption==Text)
	{
		if(m_TextCurve)
		{
			SetCursor( m_Cross);
			CClientDC dc(this);
			OnPrepareDC(&dc);
			
			CPoint pt = point;
			dc.DPtoLP(&pt);
//			ClientToDib(pt);
			if(m_pDoc->pHead!=NULL)
			{
//				CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
				int nOldRop = dc.SetROP2(R2_NOTXORPEN);
				
				dc.MoveTo(temppoint);
				dc.LineTo(endpoint);
				
				dc.MoveTo(temppoint);
				dc.LineTo(pt);
				dc.SetROP2(nOldRop);
//				m_pDoc->curptr->dib->EndPaint();
			}
//			Invalidate(false);
//			temppoint=point;
			endpoint=pt;
		}
		else
		  SetCursor(m_Text);
	}
	else if(m_ToolOption==CURVE)
	{
		SetCursor(m_Cross);
        if(m_TextCurve&&(!flagLB))
		{		
			CClientDC dc(this);
			OnPrepareDC(&dc);
			CPoint pt = point;
			dc.DPtoLP(&pt);
			ClientToDib(pt);	
			int nOldRop = dc.SetROP2(R2_NOTXORPEN);
            temppoint=m_pDoc->pCurPt->point;
			DibToClient(temppoint);
			if(pos.x!=-100)
			{
				dc.MoveTo(temppoint);
				dc.LineTo(pos);
			}
			dc.MoveTo(temppoint);
			CPoint postemp=pt;
			DibToClient(postemp);
			dc.LineTo(postemp);
			dc.SetROP2(nOldRop);
		    pos=pt;
		    DibToClient(pos);
		    endpoint=pt;	
		}
	}
	else if(m_ToolOption==PAINT)
		SetCursor(m_Paint);

	else if (m_bDrawFreeline)
	{
		m_InValidateRect=true;
		CPen pen(m_nPenStyle, m_nPenWidth, m_crPenColor);

		CClientDC dc(this);
		OnPrepareDC(&dc);

		CPoint pt = point;
	    dc.DPtoLP(&pt);
		ClientToDib(pt);

    	CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
		CPen* pOldPen = pDibDC->SelectObject(&pen);
		pDibDC->MoveTo(startpoint);
		pDibDC->LineTo(pt);
		pDibDC->SelectObject(pOldPen);
		m_pDoc->curptr->dib->EndPaint();

        int width=int(m_nPenWidth*m_fScale+3.5);
        CRect rect;
		if(startLpPoint.x<point.x)
		{
			rect.left=startLpPoint.x-width;
			rect.right=point.x+width;
		}
		else
		{
			rect.left=point.x-width;
			rect.right=startLpPoint.x+width;
		}
		if(startLpPoint.y<point.y)
		{
			rect.top=startLpPoint.y-width;
			rect.bottom=point.y+width;
		}
		else
		{
			rect.top=point.y-width;
			rect.bottom=startLpPoint.y+width;
		}
		m_InVRect=rect;
		InvalidateRect(rect,false);
		startpoint = pt;
		startLpPoint=point;
	}

	else if (m_bErasing)
	{
		// set a pixel anywaym_crFillColor
		m_InValidateRect=true;

		CPen pen(m_nPenStyle, m_nPenWidth, m_crFillColor);

		CClientDC dc(this);
		OnPrepareDC(&dc);

		CPoint pt = point;
	    dc.DPtoLP(&pt);
		ClientToDib(pt);
		CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
		CPen* pOldPen = pDibDC->SelectObject(&pen);
		pDibDC->MoveTo(startpoint);
		pDibDC->LineTo(pt);
		pDibDC->SelectObject(pOldPen);
		m_pDoc->curptr->dib->EndPaint();
        int width=int(m_nPenWidth*m_fScale+3.5);
        CRect rect;
		if(startLpPoint.x<point.x)
		{
			rect.left=startLpPoint.x-width;
			rect.right=point.x+width;
		}
		else
		{
			rect.left=point.x-width;
			rect.right=startLpPoint.x+width;
		}
		if(startLpPoint.y<point.y)
		{
			rect.top=startLpPoint.y-width;
			rect.bottom=point.y+width;
		}
		else
		{
			rect.top=point.y-width;
			rect.bottom=startLpPoint.y+width;
		}
		m_InVRect=rect;
		InvalidateRect(rect,false);
		startpoint = pt;
		startLpPoint=point;
	}
    else if(m_bDrawRect)
	{
		SetCursor(m_Cross);
		CPen pen(m_nPenStyle, 1, RGB(0,0,0));
		
		CClientDC dc(this);
		OnPrepareDC(&dc);
		int nOldRop;
		CPen* pOldPen;
		CPoint pt = point;
		dc.DPtoLP(&pt);
		nOldRop = dc.SetROP2(R2_NOTXORPEN);
		pOldPen = dc.SelectObject(&pen);

⌨️ 快捷键说明

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