Bitmap 处理相关

None.gif // 利用资源文件
None.gif
void  CBitmap1View::OnPaint() 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    CPaintDC dc(
this); // device context for painting
InBlock.gif    
InBlock.gif    
// TODO: Add your message handler code here
InBlock.gif
    CBitmap BmpLady;
InBlock.gif    CDC MemDCLady;
InBlock.gif
InBlock.gif    
// Load the bitmap from the resource
InBlock.gif
    BmpLady.LoadBitmap(IDB_LADY);
InBlock.gif    
// Create a memory device compatible with the above CPaintDC variable
InBlock.gif
    MemDCLady.CreateCompatibleDC(&dc);
InBlock.gif    
// Select the new bitmap
InBlock.gif
    CBitmap *BmpPrevious = MemDCLady.SelectObject(&BmpLady);
InBlock.gif
InBlock.gif    
// Copy the bits from the memory DC into the current dc
InBlock.gif
    dc.BitBlt(2010436364&MemDCLady, 00, SRCCOPY);
InBlock.gif
InBlock.gif    
// Restore the old bitmap
InBlock.gif
    dc.SelectObject(BmpPrevious);
InBlock.gif    
// Do not call CView::OnPaint() for painting messages
ExpandedBlockEnd.gif
}

None.gif
None.gif
// 从文件获得
None.gif
void  CDialog1Dlg::OnPaint()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    CPaintDC dc(
this); // device context for painting
InBlock.gif

InBlock.gif    
if (IsIconic())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        SendMessage(WM_ICONERASEBKGND,
InBlock.gif                reinterpret_cast
<WPARAM>(dc.GetSafeHdc()),
InBlock.gif                
0);
InBlock.gif
InBlock.gif        
// Center icon in client rectangle
InBlock.gif
        int cxIcon = GetSystemMetrics(SM_CXICON);
InBlock.gif        
int cyIcon = GetSystemMetrics(SM_CYICON);
InBlock.gif        CRect rect;
InBlock.gif        GetClientRect(
&rect);
InBlock.gif        
int x = (rect.Width() - cxIcon + 1/ 2;
InBlock.gif        
int y = (rect.Height() - cyIcon + 1/ 2;
InBlock.gif
InBlock.gif        
// Draw the icon
InBlock.gif
        dc.DrawIcon(x, y, m_hIcon);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        CDialog::OnPaint();
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    HBITMAP bmpHandle 
= (HBITMAP)LoadImage(NULL,
InBlock.gif                                       strPictureName,
InBlock.gif                           IMAGE_BITMAP,
InBlock.gif                           
0,
InBlock.gif                           
0,
InBlock.gif                           LR_LOADFROMFILE);
InBlock.gif    CBitmap bmpPicture;
InBlock.gif    CDC mdcPicture;
InBlock.gif    CBitmap 
*bmpFromHandle = bmpPicture.FromHandle(bmpHandle);
InBlock.gif
InBlock.gif    CRect rctPicture;
InBlock.gif    m_Picture.GetWindowRect(
&rctPicture);
InBlock.gif        
InBlock.gif    mdcPicture.CreateCompatibleDC(
&dc);
InBlock.gif    CBitmap 
* bmpPrevious = mdcPicture.SelectObject(bmpFromHandle);
InBlock.gif
InBlock.gif    ScreenToClient(
&rctPicture);
InBlock.gif
InBlock.gif    dc.BitBlt(rctPicture.left, rctPicture.top,
InBlock.gif          rctPicture.Width(), rctPicture.Height(),
InBlock.gif          
&mdcPicture, 00, SRCCOPY);
InBlock.gif
InBlock.gif    dc.SelectObject(bmpPrevious);
InBlock.gif    DeleteObject(bmpHandle);
ExpandedBlockEnd.gif}

None.gif
None.gif
// 在视图类中处理
None.gif
void  CShowPicture1View::OnFileOpen()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
// TODO: Add your command handler code here
ExpandedSubBlockStart.gifContractedSubBlock.gif
    TCHAR strFilter[] = dot.gif{ TEXT("Picture Files (*.bmp)|*.bmp||") };
InBlock.gif    CFileDialog dlg(TRUE, TEXT(
".bmp"), NULL, 0, strFilter);
InBlock.gif
InBlock.gif    
if( dlg.DoModal() == IDOK )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        strFilename 
= dlg.GetFileName();
InBlock.gif        Invalidate();
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
void  CShowPicture1View::OnDraw(CDC *  pDC)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    CShowPicture1Doc
* pDoc = GetDocument();
InBlock.gif    ASSERT_VALID(pDoc);
InBlock.gif    
if (!pDoc)
InBlock.gif        
return;
InBlock.gif
InBlock.gif    
// TODO: add draw code for native data here
InBlock.gif
    if( strFilename != "" )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        BITMAP bmpProperties;
InBlock.gif
InBlock.gif        
// Create a bitmap handle using the name of the file
InBlock.gif
        HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,
InBlock.gif                                           strFilename,
InBlock.gif                                   IMAGE_BITMAP,
InBlock.gif                                   
0,
InBlock.gif                               
0,
InBlock.gif                               LR_LOADFROMFILE);
InBlock.gif
InBlock.gif        CBitmap bmpPicture;
InBlock.gif        CDC mdcPicture;
InBlock.gif
InBlock.gif    
// Convert the Win32 bitmap handle into an MFC bitmap object
InBlock.gif
        CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);
InBlock.gif        bmpPicture.Attach(bmpHandle);
InBlock.gif
InBlock.gif    
// Call the Win32 GetObject() function to get the properties
InBlock.gif        
// of the bitmap and store them in a BITMAP structure
InBlock.gif
        ::GetObject(bmpPicture,
InBlock.gif                
sizeof(bmpProperties),
InBlock.gif                
&bmpProperties);
InBlock.gif
InBlock.gif        
// Create a compatible device context
InBlock.gif
        mdcPicture.CreateCompatibleDC(pDC);
InBlock.gif        
// Select the bitmap into the device context
InBlock.gif
        CBitmap * bmpPrevious = 
InBlock.gif                mdcPicture.SelectObject(bmpFromHandle);
InBlock.gif
InBlock.gif        
// Using the dimensions store in the BITMAP object,
InBlock.gif        
// display the picture
InBlock.gif
        pDC->BitBlt(00,
InBlock.gif                bmpProperties.bmWidth, bmpProperties.bmHeight,
InBlock.gif                
&mdcPicture, 00, SRCCOPY);
InBlock.gif
InBlock.gif        
// Get the dimensions of the new picture
InBlock.gif
        SIZE sizeTotal;
InBlock.gif        sizeTotal.cx 
= bmpProperties.bmWidth;
InBlock.gif        sizeTotal.cy 
= bmpProperties.bmHeight;
InBlock.gif        
// Change the scrolling area/dimensions of the view
InBlock.gif
        SetScrollSizes(MM_TEXT, sizeTotal);
InBlock.gif
InBlock.gif        
// Restore the bitmap
InBlock.gif
        pDC->SelectObject(bmpPrevious);
InBlock.gif        
// Delete the Win32 bitmap handle
InBlock.gif
        DeleteObject(bmpHandle);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif 
None.gif
void  CCView4View::OnDraw(CDC *  pDC)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    CCView4Doc
* pDoc = GetDocument();
InBlock.gif    ASSERT_VALID(pDoc);
InBlock.gif
InBlock.gif    CBitmap Bmp;
InBlock.gif    CBrush brBits;
ExpandedSubBlockStart.gifContractedSubBlock.gif    WORD wBits[] 
= dot.gif0x000x220x440x880x000x220x440x88,
InBlock.gif                
0x220x440x880x000x220x440x880x00,
InBlock.gif                
0x440x880x000x220x440x880x000x22,
ExpandedSubBlockEnd.gif                
0x880x000x220x440x880x000x220x44 }
;
InBlock.gif
InBlock.gif    Bmp.CreateBitmap(
323211, wBits);
InBlock.gif
InBlock.gif    brBits.CreatePatternBrush(
&Bmp);
InBlock.gif    CBrush
* pOldBrush = (CBrush*)pDC->SelectObject(&brBits);
InBlock.gif
InBlock.gif    pDC
->Rectangle(2020400400);
InBlock.gif
InBlock.gif    pDC
->SelectObject(&Bmp);
ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/chenfanwen/archive/2007/06/20/790836.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值