📄 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 12:55:28$
*/
#pragma once
#include <AtlZoom.h>
#include <BvcDib.h>
#include <BvcColorConverter.h>
using namespace Bvc;
const CColorConverter::PatternOrigin_t BAYER_HOME = CColorConverter::poGB;
//! 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;
//! Default constructor
CBitmapView()
{
}
//! 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, bool isColor = false)
{
// If old and new bitmap anre NULL
if(!m_ptrBitmap && !ptrNewBitmap)
return;
// If new bitmap is NULL
if((bool)m_ptrBitmap && !ptrNewBitmap)
{
SetScrollOffset(0, 0, FALSE);
SetScrollSize(CSize(1,1));
}
// If new bitmap has another size than the old one...
else if( !m_ptrBitmap && (bool)ptrNewBitmap
|| m_ptrBitmap->GetSize() != ptrNewBitmap->GetSize() )
{
SetScrollOffset(0, 0, FALSE);
SetScrollSize(ptrNewBitmap->GetSize());
}
if(isColor)
{
// Convert the image from Bayer to RGB
CColorConverter::ConvertMono8ToRGB(m_ptrBitmap,ptrNewBitmap,BAYER_HOME);
}
else
{
// Stores the bitmap directly
m_ptrBitmap = ptrNewBitmap;
}
// Invalidates the view causing a WM_PAINT message
Invalidate();
}
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);
if(!m_ptrBitmap)
{
// Compute the viewport's coordinates in logical (image-) coordinates.
RECT rect;
GetClientRect(&rect);
dc.DPtoLP(&rect);
dc.FillRect(&rect, (HBRUSH)(COLOR_WINDOW + 1));
return 0;
}
CSize Size;
m_ptrBitmap->GetSize(&Size);
int x = Size.cx + 1;
int y = Size.cy + 1;
// Compute the viewport's coordinates in logical (image-) coordinates.
RECT rect;
GetClientRect(&rect);
dc.DPtoLP(&rect);
// If the viewport is wider than the image draw a right margin
if(rect.right > Size.cx)
{
RECT rectRight = rect;
rectRight.left = x;
rectRight.bottom = y;
dc.FillRect(&rectRight, (HBRUSH)(COLOR_WINDOW + 1));
}
// If the viewport is higher than the image draw a bottom margin
if(rect.bottom > Size.cy)
{
RECT rectBottom = rect;
rectBottom.top = y;
dc.FillRect(&rectBottom, (HBRUSH)(COLOR_WINDOW + 1));
}
// If there is an image draw a border between the margins and the image
if(!m_ptrBitmap)
{
dc.MoveTo(Size.cx, 0);
dc.LineTo(Size.cx, Size.cy);
dc.LineTo(0, Size.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(0, 0, Size.cx, Size.cy));
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, rect.left, rect.top, SRCCOPY);
dcMem.SelectBitmap(hBmpOld);
}
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -