📄 piccontrol.cpp
字号:
// PicContro.cpp: implementation of the CPicContro class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "QuickImage.h"
#include "PicControl.h"
#include "raw.h"
//#include "gemfile.h"
//#include "MathEx.h"
#include "dibapi.h"
#include "imports\jpegfile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
double CPicControl::ViewFit(CPoint &ptDIBCent, const CRect &rcView, const HDIB hDIB)
{
ASSERT(NULL != hDIB);
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
long cxDIB = ::DIBWidth(lpDIB); // Size of DIB - x
long cyDIB = abs(::DIBHeight(lpDIB)); // Size of DIB - y
::GlobalUnlock((HGLOBAL) hDIB);
double dX= (double)cxDIB/rcView.Width();
double dY= (double)cyDIB/rcView.Height();
double dZoom = dX > dY ? dX : dY;
ptDIBCent.x = cxDIB/2;
ptDIBCent.y = cyDIB/2;
return dZoom;
}
double CPicControl::ViewActual(CPoint &ptDIBCent, const CRect &rcView, const HDIB hDIB)
{
ASSERT(NULL != hDIB);
// ASSERT(NULL != pView);
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
long cxDIB = ::DIBWidth(lpDIB); // Size of DIB - x
long cyDIB = abs(::DIBHeight(lpDIB)); // Size of DIB - y
::GlobalUnlock((HGLOBAL) hDIB);
ptDIBCent.x = cxDIB < rcView.Width() ? cxDIB/2 : rcView.Width()/2;
ptDIBCent.y = cyDIB < rcView.Height() ? cyDIB/2 : rcView.Height()/2;
return 1.0;
}
double CPicControl::ZoomIn(double dZoom)
{
dZoom *= 2.0;
if(dZoom > 10)
{
dZoom=10.0;
}
return dZoom;
}
double CPicControl::ZoomOut(double dZoom)
{
dZoom /= 2.0;
if(dZoom < 0.01)
{
dZoom=0.01;
}
return dZoom;
}
double CPicControl::ZoomPan(CPoint &ptDIBCent,
const CPoint &ptMouseD, const CPoint& ptMouseU, double dZoom)
{
ptDIBCent.x -= int((ptMouseU.x-ptMouseD.x) * dZoom);
ptDIBCent.y -= int((ptMouseU.y-ptMouseD.y) * dZoom);
return dZoom;
}
double CPicControl::ZoomWindow(CPoint &ptDIBCent,
const CRect &rcView, CRect &rcWindow, double dZoom)
{
// ASSERT(NULL != hDIB);
// ASSERT(NULL != pView);
rcWindow.NormalizeRect();
if((rcWindow.Width() < 10) || (rcWindow.Height() <10))
{
return dZoom;
}
CPoint ptWindow,ptView;
ptWindow = rcWindow.CenterPoint();
ptView = rcView.CenterPoint();
ptDIBCent.x += long((ptWindow.x-ptView.x) * dZoom);
ptDIBCent.y += long((ptWindow.y-ptView.y) * dZoom);
double dX,dY;
dX = (double)rcView.Width() / rcWindow.Width();
dY = (double)rcView.Height() / rcWindow.Height();
dZoom /= (dX < dY ? dX : dY);
return dZoom;
}
void CPicControl::CalcuRect(CRect& rcView, CRect& rcDIB,
const CPoint &ptDIBCent, const HDIB hDIB, double dZoom)
{
ASSERT(NULL != hDIB);
// ASSERT(NULL != pView);
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
long cxDIB = ::DIBWidth(lpDIB); // Size of DIB - x
long cyDIB = abs(::DIBHeight(lpDIB)); // Size of DIB - y
::GlobalUnlock((HGLOBAL) hDIB);
int iDCMid = rcView.CenterPoint().x;
double dDIBDiff = ptDIBCent.x / dZoom;
if(iDCMid < dDIBDiff)
{
rcDIB.left = ptDIBCent.x - int(iDCMid * dZoom);
}
else
{
rcView.left = iDCMid - (int)dDIBDiff;
rcDIB.left = 0;
}
dDIBDiff = (cxDIB - ptDIBCent.x) / dZoom;
if(iDCMid < dDIBDiff)
{
rcDIB.right = ptDIBCent.x + int(iDCMid * dZoom);
}
else
{
rcView.right = iDCMid + (int)dDIBDiff;
rcDIB.right = cxDIB;
}
iDCMid = rcView.CenterPoint().y;
dDIBDiff = ptDIBCent.y / dZoom;
if(iDCMid < dDIBDiff)
{
rcDIB.top = ptDIBCent.y - int(iDCMid * dZoom);
}
else
{
rcView.top = iDCMid - int(ptDIBCent.y / dZoom);
rcDIB.top = 0;
}
dDIBDiff = (cyDIB - ptDIBCent.y) / dZoom;
if(iDCMid < dDIBDiff)
{
rcDIB.bottom = ptDIBCent.y + int(iDCMid * dZoom);
}
else
{
rcView.bottom = iDCMid + (int)dDIBDiff;
rcDIB.bottom = cyDIB;
}
if(rcDIB.top == 0)
{
rcDIB.top = cyDIB - rcDIB.Height();
rcDIB.bottom = cyDIB;
}
if(rcView.top == 0)
{
cxDIB = cyDIB - rcDIB.bottom;
rcDIB.bottom = cyDIB - rcDIB.top;
rcDIB.top = cxDIB;
}
}
void CPicControl::ViewIdeal(CPoint &ptDIBCent, double &dZoom,
const CView *pView, const HDIB hDIB)
{
ASSERT(NULL != hDIB);
ASSERT(NULL != pView);
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
long cxDIB = ::DIBWidth(lpDIB); // Size of DIB - x
long cyDIB = abs(::DIBHeight(lpDIB)); // Size of DIB - y
::GlobalUnlock((HGLOBAL) hDIB);
ptDIBCent.x = cxDIB / 2;
ptDIBCent.y = cyDIB / 2;
CRect rcDC;
pView->GetClientRect(&rcDC);
rcDC.InflateRect(-2, -2);
double dx = (double)rcDC.Width() / cxDIB;
double dy = (double)rcDC.Height() / cyDIB;
if((dx > 1.0) && (dy > 1.0))
{
dZoom = 1.0;
}
else
{
dZoom = dx > dy ? dx : dy;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -