📄 bitmapview.h
字号:
/*! \file BitmapView.h
\brief Interface and implementation of the CBitmapView class
Company: Basler Vision Technologies
Section: Vision Components
Project: 1394 Driver
$Author: Nebelung, H.$
$Revision: 1$
$Date: 27.09.2002 16:11:26$
*/
#pragma once
#include <AtlZoom.h>
#include <BvcColorConverter.h>
using namespace Bvc;
//! Displays the bitmap handling zooming, panning etc.
class CBitmapView :
public CZoomWindowImpl<CBitmapView>
{
public:
DECLARE_WND_CLASS_EX(NULL, 0, -1)
//! The bitmap to be shown
CDibPtr m_ptrBitmap;
//! Position of the upper left corner of the bitmap with respect ti the imager
CPoint m_AoiPosition;
//! The total size of the image
CSize m_ImageSize;
//! Default constructor
CBitmapView()
{
}
void SetImageSize(CSize ImageSize)
{
m_ImageSize = ImageSize;
SetScrollOffset(0, 0, FALSE);
SetScrollSize(ImageSize);
Invalidate();
}
//! Handles messages before they are forwarded to the message handlers
BOOL PreTranslateMessage(MSG* /*pMsg*/)
{
return FALSE;
}
//! Releases any bitmap which is hold by the view
void ReleaseBitmap()
{
m_ptrBitmap.Release();
SetScrollOffset(0, 0, FALSE);
SetScrollSize(CSize(1,1));
// Invalidates the view causing a WM_PAINT message
Invalidate();
}
//! Sets this bitmap to be displayed and refreshes the display
void SetBitmap(CDibPtr &ptrNewBitmap, CPoint AoiPosition)
{
bool NewImage = false;
NewImage |= (!m_ptrBitmap && ptrNewBitmap);
NewImage |= (m_ptrBitmap && !ptrNewBitmap);
NewImage |= (m_ptrBitmap && !m_ptrBitmap->IsEqualType(*ptrNewBitmap));
m_ptrBitmap = ptrNewBitmap;
m_AoiPosition = AoiPosition;
// Invalidates the view causing a WM_PAINT message
// erases the background only if a new image type arrives
Invalidate(NewImage);
}
BEGIN_MSG_MAP(CBitmapView)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
CHAIN_MSG_MAP(CZoomWindowImpl<CBitmapView>)
END_MSG_MAP()
//! Draws the background
/*! The image is aligned to the upper left corner of the viewport.
In case the image is smaller than the viewport a right margin
and a bottom margin are drawn.
*/
LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CDCHandle dc = (HDC)wParam;
PrepareDC(dc);
// Compute the viewport's coordinates in logical (image-) coordinates.
RECT rect;
GetClientRect(&rect);
dc.DPtoLP(&rect);
dc.FillRect(&rect, (HBRUSH)(COLOR_WINDOW + 1));
// If there is an image draw a border between the margins and the image
if(m_ptrBitmap)
{
dc.MoveTo(m_ImageSize.cx, 0);
dc.LineTo(m_ImageSize.cx, m_ImageSize.cy);
dc.LineTo(0, m_ImageSize.cy);
}
return 0;
}
//! Draws the image.
/*! The image is aligned to the upper left corner of the viewport. */
void DoPaint(CDCHandle dc)
{
if((bool)m_ptrBitmap)
{
// Compute the viewport's coordinates in logical (image-) coordinates.
CRect rect;
GetClientRect(&rect);
dc.DPtoLP(&rect);
// Make sure to draw only those parts of the image which are visible in the viewport
CSize Size;
m_ptrBitmap->GetSize(&Size);
rect.IntersectRect(rect, CRect(m_AoiPosition, Size));
rect.InflateRect(1,1);
// Draw the image
//! \todo Handle the case that the graphics card uses a palette
CDC dcMem;
dcMem.CreateCompatibleDC(dc);
HBITMAP hBmpOld = dcMem.SelectBitmap(m_ptrBitmap->GetBitmapHandle());
if( m_dZoomScale < 1 )
{
dc.SetStretchBltMode(COLORONCOLOR);
}
dc.BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), dcMem, 0, 0, SRCCOPY);
dcMem.SelectBitmap(hBmpOld);
// Draw a box around the image
dc.FrameRect(rect, (HBRUSH)(COLOR_WINDOW + 1));
}
}
//! Called if zoom-level changes. Erase the whole backgroung
virtual void ZoomLevelChanged(void)
{
Invalidate();
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -