CodeForge QQ客服 CodeForge 400电话 客服电话 4006316121

ImageView.cpp ( 文件浏览 )

  • 发布于2010-11-24
  • 浏览次数:30
  • 下载次数:1
  • 下载需 1 积分
  • 侵权举报
			// ImageView.cpp : implementation file
//

#include "stdafx.h"
#include "ImageView.h"
#include "ImageDoc.h"

//{
{

#include "MainFrm.h"
//
}
}
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CImageView

IMPLEMENT_DYNCREATE(CImageView, CFormView)

BEGIN_MESSAGE_MAP(CImageView, CFormView)
	//{
{
AFX_MSG_MAP(CImageView)
	ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
	ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditClear)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
	ON_COMMAND(ID_EDIT_CUT, OnEditCut)
	ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
	ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
	ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
	ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
	ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
	ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDBLCLK()
	ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
	ON_WM_ERASEBKGND()
	//
}
}AFX_MSG_MAP
END_MESSAGE_MAP()


CImageView::CImageView()
	: CFormView(CImageView::IDD)
{

	//{
{
AFX_DATA_INIT(CImageView)
		// NOTE: the ClassWizard will add member initialization here
	//
}
}AFX_DATA_INIT
	InitData();

}

CImageView::CImageView( LPCTSTR lpszTemplateName )
	:CFormView(lpszTemplateName) 
{

	InitData();

}

CImageView::CImageView( UINT nIDTemplate )
	:CFormView(nIDTemplate)
{

	InitData();

}
//初始化成员数据
void CImageView::InitData()
{

	m_nUndoStackDeep = 5;//Undo/Redo堆栈深度
	m_nAutoCommand=NULL;
	m_bAutoProcessing=FALSE;
	m_nRegionCombineMode=RGN_COPY;
	m_nRegionFillMode=WINDING;
	m_nZoomFactor=100; //100%
	m_nMouseFunction=MOUSE_REGION;
    m_nRegionTool=RGNMARK_FREEHAND;

	m_stkUnRedo.SetStackDeep(m_nUndoStackDeep);

}

CImageView::~CImageView()
{

	m_Region.Clear();
	m_Region.DeleteObject();

}

void CImageView::DoDataExchange(CDataExchange* pDX)
{

	CFormView::DoDataExchange(pDX);
	//{
{
AFX_DATA_MAP(CImageView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//
}
}AFX_DATA_MAP

}


/////////////////////////////////////////////////////////////////////////////
// CImageView diagnostics

#ifdef _DEBUG
void CImageView::AssertValid() const
{

	CFormView::AssertValid();

}

void CImageView::Dump(CDumpContext& dc) const
{

	CFormView::Dump(dc);

}

CImageDoc* CImageView::GetDocument() // non-debug version is inline
{

//  为利于子类重载,去除该断言 
//	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageDoc)));
	return (CImageDoc*)m_pDocument;

}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CImageView message handlers
//文档坐标与客户区坐标变换
void CImageView::ClientToDoc(CPoint& point)
{

//	CClientDC dc(this);
//	OnPrepareDC(&dc, NULL);
//	dc.DPtoLP(&point);
	point.x+=GetScrollPos(SB_HORZ),
	point.y+=GetScrollPos(SB_VERT);


}

void CImageView::ClientToDoc(CRect& rect)
{

//	CClientDC dc(this);
//	OnPrepareDC(&dc, NULL);
//	dc.DPtoLP(rect);
	rect.left+=GetScrollPos(SB_HORZ),
	rect.right+=GetScrollPos(SB_HORZ),
	rect.top+=GetScrollPos(SB_VERT);
	rect.bottom+=GetScrollPos(SB_VERT);

	ASSERT(rect.left <= rect.right);
	ASSERT(rect.bottom <= rect.top);

}

//该函数不完善
void CImageView::ClientToDoc(CRgn& rgn)
{

	rgn.OffsetRgn(GetScrollPos(SB_HORZ),
	              GetScrollPos(SB_VERT));

}

void CImageView::DocToClient(CPoint& point)
{

//	CClientDC dc(this);
//	OnPrepareDC(&dc, NULL);
//	dc.LPtoDP(&point);
	point.x-=GetScrollPos(SB_HORZ),
	point.y-=GetScrollPos(SB_VERT);


}

void CImageView::DocToClient(CRect& rect)
{

//	CClientDC dc(this);
//	OnPrepareDC(&dc, NULL);
//	dc.LPtoDP(rect);
	rect.left-=GetScrollPos(SB_HORZ),
	rect.right-=GetScrollPos(SB_HORZ),
	rect.top-=GetScrollPos(SB_VERT);
	rect.bottom-=GetScrollPos(SB_VERT);
	rect.NormalizeRect();

}

//该函数不完善
void CImageView::DocToClient(CRgn& rgn)
{

	rgn.OffsetRgn(-GetScrollPos(SB_HORZ),
	              -GetScrollPos(SB_VERT));


}

/////////////////////////////////////////////////////////////////////////////
// CImageView 绘制
void CImageView::OnInitialUpdate()
{

	CFormView::OnInitialUpdate();
	ASSERT(GetDocument() != NULL);

	// TODO: calculate the total size of this view
    CSize size=GetDocument()->GetDocSize();
	SetScrollSizes(MM_TEXT, size);

	//设置初始区域为全图象
	CRgn rgnImage;
	rgnImage.CreateRectRgn(0,0,size.cx,size.cy);
	m_Region.DeleteObject();
	m_Region.Attach(rgnImage.Detach());


}

void CImageView::OnDraw(CDC* pDC) 
{

	// TODO: Add your specialized code here and/or call the base class
	ASSERT_VALID(pDC);
	CImageDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	HDIB hDIB = pDoc->GetHDIB();

	//1998.12.26设置背景色
	CBrush brush(HS_DIAGCROSS,RGB(192,192,192) );
	if(!pDC->IsPrinting())
	{

		pDC->SetBkColor(RGB(255,255,255));
		CRect rectWnd;
		GetClientRect(&rectWnd);
		rectWnd.right*=5;rectWnd.bottom*=5;//暂时用此下策
		pDC->FillRect(&rectWnd,&brush);
	
}
	if (hDIB != NULL)
	{

		//由句柄取得位图指针	
		LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
	
		//由句柄取得位图宽高	
		int cxDIB = (int) ::DIBWidth(lpDIB);         // Size of DIB - x
		int cyDIB = (int) ::DIBHeight(lpDIB);        // Size of DIB - y
		
		::GlobalUnlock((HGLOBAL) hDIB);
		

		//确定显示区域大小
		CRect rcDIB;
		rcDIB.top = rcDIB.left = 0;
		rcDIB.right = cxDIB;
		rcDIB.bottom = cyDIB;
		CRect rcDest;
		
	
		if (pDC->IsPrinting())   // printer DC
		{

			// 取得打印机纸张大小(in pixels)
			int cxPage = pDC->GetDeviceCaps(HORZRES);
			int cyPage = pDC->GetDeviceCaps(VERTRES);
			// 取得打印机 pixels per inch
			int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
			int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);

			//
			// Best Fit case -- create a rectangle which preserves
			// the DIB's aspect ratio, and fills the page horizontally.
			//
			// The formula in the "->bottom" field below calculates the Y
			// position of the printed bitmap, based on the size of the
			// bitmap, the width of the page, and the relative size of
			// a printed pixel (cyInch / cxInch).
			//
			rcDest.top = rcDest.left = 0;
			rcDest.bottom = (int)(((double)cyDIB * cxPage * cyInch)
					/ ((double)cxDIB * cxInch));
			rcDest.right = cxPage;
		
}
		else   // not printer DC
		{

			rcDest = rcDIB;
			//{
{
  图象缩放显示
		    rcDest.bottom=int(rcDest.bottom * m_nZoomFactor/100);    
			rcDest.right =int(rcDest.right *  m_nZoomFactor/100); 
			//
}
}
		
}
		
		//显示
	    pDC->FillRect(&rcDest,&brush);
		::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
			&rcDIB, pDoc->GetDocPalette());

		//绘制选中区域的边框
		if(!pDC->IsPrinting())
		{

			CBrush brush(RGB(0,128,128));
			pDC->SetROP2(R2_NOT);
			pDC->FrameRgn(&m_Region,&brush,1,1);
			pDC->SetROP2(R2_COPYPEN);
		
}

	
}

}
//通用处理开始函数
//操作    :设置m_entryImage,设置等待光标,准备Undo
//返回值   TRUE  成功
//         FALSE 失败
BOOL CImageView::BeginProcessing()
{

	CImageDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	m_entryImage.hDIB=NULL;					//源位图句柄
	m_entryImage.hNewDIB=NULL;				//生成目标位图句柄
	m_entryImage.pImage=NULL;				//源位图数据开始位(用于灰度图)
	m_entryImage.pNewImage=NULL;			//目标位图数据开始位(用于灰度图)
	m_entryImage.hBitmap=NULL;				//源临时中间设备相关位图句柄
	m_entryImage.hNewBitmap=NULL;			//目标临时中间设备相关位图句柄
	m_entryImage.hMemDC=NULL;				//源位图设备
	m_entryImage.hNewDC=NULL;				//目标位图设备
	m_entryImage.rectImage=CRect(0,0,1,1);		//包围选中区域的最小矩形
	m_entryImage.sizeImage=CSize(1,1);		//图象大小

	if(pDoc->GetHDIB()==NULL) return FALSE;
	//求出包围区域的最小矩形
	if(m_Region.m_hObject == NULL ) return FALSE;
	m_Region.GetRgnBox(&(m_entryImage.rectImage));
	if(m_entryImage.rectImage.right-2<=m_entryImage.rectImage.left ||
		m_entryImage.rectImage.bottom-2<=m_entryImage.rectImage.top)
	{

		AfxMessageBox(_T("选定的处理区域无效"));
		return FALSE;
	
}
	BeginWaitCursor();
//	ReplaceHandleForUndo((HGLOBAL)pDoc->GetHDIB());
	m_stkUnRedo.PushUndo(CopyHandle((HGLOBAL)pDoc->GetHDIB()));
	
	m_entryImage.sizeImage.cx=pDoc->GetDocSize().cx;
	m_entryImage.sizeImage.cy=pDoc->GetDocSize().cy;
	return TRUE;

}
///////////////////////////////////////////////////
//灰度处理开始函数
//返回值   TRUE  成功
//         FALSE 失败
//         pNewImage是pImage的副本
///////////////////////////////////////////////////
BOOL CImageView::BeginProcessingGray()
{


	CImageDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	BeginProcessing();
	
	LPBITMAPINFOHEADER  lpBi,lpNewBi;

	m_entryImage.hDIB=pDoc->GetHDIB();
	lpBi=(LPBITMAPINFOHEADER)::GlobalLock((HGLOBAL)	m_entryImage.hDIB);//取得原有位图
	m_entryImage.pImage=(BYTE FAR*)::FindDIBBits((LPSTR)lpBi);

	m_entryImage.hNewDIB=(HDIB)::CopyHandle((HGLOBAL)m_entryImage.hDIB);//建立一个新位图
	lpNewBi=(LPBITMAPINFOHEADER)::GlobalLock((HGLOBAL)m_entryImage.hNewDIB);
	m_entryImage.pNewImage=(BYTE FAR*)::FindDIBBits((LPSTR)lpNewBi);
	return TRUE;

}
///////////////////////////////////////////////////
//彩色处理开始函数
//返回值   TRUE  成功
//         FALSE 失败
//         hNewBitmap是hBitmap的副本
//         hNewDC关联hNewBitmap, hMemDC关联hBitmap

BOOL CImageView::BeginProcessingColor()
{

	CImageDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	BeginProcessing();
	
	HDC hDC=::GetDC(NULL);
	m_entryImage.hMemDC=::CreateCompatibleDC(hDC);
	m_entryImage.hNewDC=::CreateCompatibleDC(hDC);
	
	m_entryImage.hBitmap=::DIBToBitmap(pDoc->GetHDIB(), 
		//HPALETTE(
...
...
(文件超长,未完全显示,请下载后阅读剩余部分)
			
...
展开> <收缩

下载源码到电脑,阅读使用更方便

1 积分

快速下载
还剩0行未阅读,继续阅读
云测速

源码文件列表

温馨提示: 点击源码文件名可预览文件内容哦 ^_^
...
名称 大小 修改日期
011.00 B
ChildFrm.cpp2.00 kB04-03-99|22:14
ChildFrm.h1.47 kB04-03-99|22:14
COLOR.CPP3.28 kB06-07-98|18:45
Dibapi.cpp27.34 kB03-13-99|14:08
Dibapi.h2.39 kB03-17-99|19:59
File.cpp7.70 kB12-31-98|10:59
Graydoc.cpp1.45 kB04-04-99|09:14
Graydoc.h680.00 B04-04-99|09:26
GrayDocS.cpp565.00 B04-04-99|09:27
GrayDocS.h582.00 B04-04-99|09:28
Hough.cpp10.02 kB04-08-99|19:01
Hough.h708.00 B04-08-99|10:39
ImageApp.cpp4.95 kB04-06-99|11:52
ImageApp.h926.00 B04-06-99|11:51
ImageAReadMe.txt8.22 kB04-05-99|14:50
ImageDoc.cpp7.93 kB04-05-99|11:26
ImageDoc.h2.31 kB04-03-99|22:28
ImageRegion.cpp1.44 kB04-03-99|22:28
ImageRegion.h877.00 B04-03-99|22:28
ImageS.clw6.82 kB04-12-99|19:26
ImageS.cpp8.05 kB04-05-99|17:22
ImageS.dsp12.17 kB11-25-02|00:16
ImageS.dsw537.00 B04-08-99|13:44
ImageS.h1.33 kB04-05-99|17:22
ImageS.idl402.00 B04-05-99|17:22
ImageS.rc21.37 kB04-08-99|10:27
ImageS.reg1.52 kB04-03-99|22:13
ImageS.rgs175.00 B04-05-99|17:22
ImageView.cpp28.45 kB04-04-99|20:48
ImageView.h6.77 kB04-03-99|22:28
ImgDocS.cpp2.30 kB04-04-99|08:28
ImgDocS.h1.64 kB04-04-99|08:29
ImgVwS.cpp10.22 kB04-08-99|13:36
ImgVwS.h2.29 kB04-08-99|10:09
IpFrame.cpp3.80 kB04-03-99|22:14
IpFrame.h1.65 kB04-03-99|22:14
MainFrm.cpp2.70 kB04-03-99|22:13
MainFrm.h1.51 kB04-03-99|22:13
MakeHelp.bat1.35 kB04-03-99|22:13
Plugins.cpp2.36 kB04-04-99|10:13
Plugins.h863.00 B04-03-99|10:06
ProgDlg.cpp7.36 kB04-03-99|22:28
ProgDlg.h2.78 kB04-03-99|22:28
Rangeann.cpp4.48 kB04-03-99|22:28
Rangeann.h1.97 kB04-03-99|22:28
ReadMe.txt4.11 kB04-05-99|16:21
011.00 B
resource.h2.07 kB04-08-99|10:27
idr_main.ico1.05 kB04-05-99|16:51
ImageS.ico1.05 kB04-05-99|16:51
ImageS.rc2398.00 B04-03-99|22:13
ImgDocS.ico1.05 kB04-03-99|22:13
IToolbar.bmp718.00 B04-06-99|21:26
Toolbar.bmp2.58 kB04-07-99|20:07
SrvrItem.cpp3.04 kB04-03-99|22:13
SrvrItem.h1.30 kB04-03-99|22:13
StdAfx.cpp294.00 B04-05-99|17:22
StdAfx.h1.51 kB04-05-99|17:22
UnRedoStack.cpp2.63 kB04-04-99|20:46
UnRedoStack.h1.88 kB03-18-99|10:32
VCTW32MS.LIB9.40 kB12-11-97|15:46
VGrayPic.cpp854.00 B04-04-99|19:10
VGrayPic.h997.00 B04-04-99|11:04
VIC32MS.LIB90.82 kB01-12-99|16:07
VICDEFS.H39.49 kB01-13-99|14:25
VicPict.cpp58.94 kB04-05-99|11:32
VicPict.h11.88 kB04-05-99|10:44
VPicEx.cpp11.22 kB04-03-99|22:28
VPicEx.h885.00 B04-03-99|22:28
云测速

ImageView.cpp (125.94 kB)

需要 1 积分
您持有 积分

CodeForge积分(原CF币)全新升级,功能更强大,使用更便捷,不仅可以用来下载海量源代码马上还可兑换精美小礼品了 了解更多

您的积分不足

支付宝优惠套餐快速获取 30 积分

订单支付完成后,积分将自动加入到您的账号。以下是优惠期的人民币价格,优惠期过后将恢复美元价格。

更多付款方式:网银PayPal

上传代码,免费获取

您本次下载所消耗的积分将转交上传作者。

同一源码,30天内重复下载,只扣除一次积分。

登录 CodeForge

还没有CodeForge账号? 立即注册
关注微博
联系客服

Switch to the English version?

Yes
CodeForge 英文版
No
CodeForge 中文版

完善个人资料,获价值¥30元积分奖励!

^_^"呃 ...

Sorry!这位大神很神秘,未开通博客呢,请浏览一下其他的吧
好的