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

📄 bitmapview.h

📁 BCAM 1394 Driver
💻 H
字号:
//-----------------------------------------------------------------------------
//  Company:  Basler Vision Technologies
//  Section:  Vision Components
//  Project:  1394 Driver
//  $Revision: 2$
//  $Date: 07.11.2002 19:37:34$
//-----------------------------------------------------------------------------
//  BitmapView.h : interface of the CBitmapView class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once
#include <AtlZoom.h>
#include <BvcDib.h>
#include <BvcColorConverter.h>
using namespace Bvc;

class CBitmapView : public CZoomWindowImpl<CBitmapView>
{
 
public:
  DECLARE_WND_CLASS_EX(NULL, 0, -1)

  //! Displays the bitmap handling zooming, panning
  CDibPtr m_ptrBitmap;

  //! Default Constructor
  CBitmapView()
  {
  }

  //! Handles messages before they are forwarded to the message handlers
  BOOL PreTranslateMessage(MSG* /*pMsg*/)
  {
    return FALSE;
  }

  //! Sets this bitmap to be displayed and refreshes the display
  void SetBitmap(CDibPtr &ptrNewBitmap, bool isTopDown = true)
  {
    // 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());
    }

    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 + -