• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            李帥的博客

            軟件開發愛好者

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              14 隨筆 :: 3 文章 :: 4 評論 :: 0 Trackbacks

            #include "stdafx.h"
            #include "DIB.h"

            IMPLEMENT_DYNAMIC(CDIB, CGdiObject);

            //////////////////////////////////////////////////////////////////////
            //
            // CDIB
            //
            // 設備無關位圖類(版本1.0)
            //
            // 完成功能:
            //     設備無關位圖的創建,顯示,讀入,保存,捕捉位圖
            //
            // 版本所有: 羅雋,曾志
            //
            //////////////////////////////////////////////////////////////////////

            //構造函數
            CDIB::CDIB() : CGdiObject()
            {
            }

            //析購函數
            CDIB::~CDIB()
            {
             DeleteObject();
            }


            //////////////////////////////////////////////////////////////////
            //
            // CreateDIB(int cx, int cy, UINT ibitcount, const void* lpBits)
            //
            // 完成功能:
            //     創建DIB位圖
            //
            // 輸入參數:
            //    圖像寬度 cx
            //     圖像高度 cy
            //     圖像位數 ibitcount
            //     圖像數據 lpBits
            //
            // 返回參數:
            //    是否成功
            //
            //////////////////////////////////////////////////////////////////

            //創建DIB位圖
            BOOL CDIB::CreateDIB(int cx, int cy, UINT ibitcount, const void* lpBits)
            {
             ASSERT((ibitcount == 1) || (ibitcount == 4) ||
               (ibitcount == 8) || (ibitcount == 16)
               || (ibitcount == 24) ||(ibitcount == 32)) ;

             // Create a BITMAPINFOHEADER structure to describe the DIB
             //創建信息頭
                int iSize = sizeof(BITMAPINFOHEADER);// + 256*sizeof(RGBQUAD);
             BITMAPINFO* pBMI;
             BYTE *pByte;

             switch(ibitcount){
              case 8:
               iSize += 4*4;
               break;
              case 1:
              case 4:
              case 16:
              case 24:
              case 32:
               break;
              default:
               break;
             }

             pByte = new BYTE[iSize];
             pBMI = (BITMAPINFO*) pByte;
                memset(pBMI, 0, iSize);

             pBMI->bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
             pBMI->bmiHeader.biWidth       = cx;
             pBMI->bmiHeader.biHeight      = cy;
             pBMI->bmiHeader.biPlanes      = 1;
             pBMI->bmiHeader.biBitCount    = ibitcount;
             pBMI->bmiHeader.biCompression = BI_RGB; // to use this flag.

             BOOL bRet = CreateDIBIndirect(pBMI, lpBits);
             delete[] pByte;
             
             return(bRet);
            }


            //////////////////////////////////////////////////////////////////
            //
            // CreateDIBIndirect(LPBITMAPINFO pBMI, const void* lpBits)
            //
            // 完成功能:
            //     創建DIB位圖
            //
            // 輸入參數:
            //    位圖信息結構指針 pBMI
            //     圖像數據 lpBits
            //
            // 返回參數:
            //    是否成功
            //
            //////////////////////////////////////////////////////////////////

            //創建DIB位圖
            BOOL CDIB::CreateDIBIndirect(LPBITMAPINFO pBMI, const void* lpBits)
            {
             //摧毀原對象
             if (m_hObject != NULL)
             {
              DeleteObject();
             }

             // Create the DIB section.
             //創建
             CDC *pDC = new CDC;
             pDC->CreateCompatibleDC(NULL);
             LPVOID pBits;
             HBITMAP hDIB = ::CreateDIBSection(pDC->GetSafeHdc(),
                   pBMI,
                   DIB_RGB_COLORS,
                                        &pBits,
                                        NULL,
                                        0);
             delete pDC;

             ASSERT(hDIB);
             ASSERT(pBits);
             Attach(hDIB);

             //拷貝圖像數據
             SetDIBBits(GetWidthBytes() * GetHeight(), lpBits);

             return TRUE;
            }


            //////////////////////////////////////////////////////////////////
            //
            // SetDIBBits(DWORD dwCount,const void * lpBits)
            //
            // 完成功能:
            //     設置圖像數據,將 lpBits 的數據拷貝至圖像
            //
            // 輸入參數:
            //    位圖數據大小 dwCount
            //     圖像數據 lpBits
            //
            // 返回參數:
            //    拷貝的數據大小
            //
            //////////////////////////////////////////////////////////////////

            // Set DIB's bits
            // 設置圖像數據
            DWORD CDIB::SetDIBBits(DWORD dwCount,const void * lpBits)
            {
             if(lpBits != NULL){
              LPVOID pBits = GetBits();
              memcpy(pBits,lpBits,dwCount);
              return dwCount;
             }
             return 0;
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetDIBBits(DWORD dwCount, LPVOID lpBits)
            //
            // 完成功能:
            //     得到圖像數據.
            //     如果 lpBits 為空,則返回圖像數據指針;
            //    如果 lpBits 不為空,
            //             則將圖像數據拷貝至該指針,
            //             并返回圖像數據指針;
            //
            // 輸入參數:
            //    拷貝的位圖數據大小 dwCount
            //     圖像數據 lpBits
            //
            // 返回參數:
            //    圖像數據指針
            //
            //////////////////////////////////////////////////////////////////

            // Get DIB's bits
            // 得到圖像數據
            LPVOID CDIB::GetDIBBits(DWORD dwCount, LPVOID lpBits)
            {
             LPVOID pBits = GetBits();
             if(lpBits != NULL){
              memcpy(lpBits,pBits,dwCount);
              return pBits;
             }
             else{
              return pBits;
             }
            }


            //////////////////////////////////////////////////////////////////
            //
            // operator = (CDIB& copy)
            //
            // 完成功能:
            //     重載賦值符
            //
            // 輸入參數:
            //    要拷貝的位圖 copy
            //
            // 返回參數:
            //    新圖像數據
            //
            //////////////////////////////////////////////////////////////////

            //重載賦值符
            CDIB& CDIB::operator = (CDIB& copy)
            {
              DIBSECTION DibSection;
             //得到原圖像信息
             copy.GetDibSection(&DibSection);
             int nSize = DibSection.dsBmih.biClrUsed*sizeof(RGBQUAD) + sizeof(BITMAPINFOHEADER);

             //申請新圖像信息頭內存
             BYTE *pByte = new BYTE[nSize];
             //拷貝信息
             memcpy(pByte, &(DibSection.dsBmih), sizeof(BITMAPINFOHEADER));

             CDC *pdc = copy.GetDC();
             //得到調色板信息
             ::GetDIBColorTable(pdc->GetSafeHdc(), 0, DibSection.dsBmih.biClrUsed,
                  (RGBQUAD*)(pByte+sizeof(BITMAPINFOHEADER)));
             copy.ReleaseDC(pdc);

             //創建新位圖
             BITMAPINFO *pBMI = (BITMAPINFO*)pByte;
             CreateDIBIndirect(pBMI);

             //拷貝圖像信息
             int nTotalSize = copy.GetWidthBytes() * copy.GetHeight();
             memcpy(GetBits(), copy.GetBits(), nTotalSize);

             delete[] pByte;
             return(*this);
            }


            //////////////////////////////////////////////////////////////////
            //
            // SetPalette(UINT uStartIndex, UINT cEntries, CONST RGBQUAD *pColors)
            //
            // 完成功能:
            //     設置調色板
            //
            // 輸入參數:
            //    調色板開始索引 uStartIndex
            //     調色板入口 cEntries
            //     顏色數據 pColors
            //
            // 返回參數:
            //    無
            //
            //////////////////////////////////////////////////////////////////

            // Set the color table in the DIB section.
            // 設置調色板
            void CDIB::SetPalette(UINT uStartIndex, UINT cEntries, CONST RGBQUAD *pColors)
            {
             HDC hdc = ::CreateCompatibleDC(NULL);
             HBITMAP hOld = (HBITMAP)::SelectObject(hdc, m_hObject);

             ::SetDIBColorTable(hdc, uStartIndex, cEntries, pColors);
             
             ::SelectObject(hdc, hOld);
             ::DeleteObject(hdc);
            }


            //////////////////////////////////////////////////////////////////
            //
            // SetPalette(CPalette* pPal)
            //
            // 完成功能:
            //     設置調色板
            //
            // 輸入參數:
            //    調色板結構指針 pPal
            //
            // 返回參數:
            //    無
            //
            //////////////////////////////////////////////////////////////////

            // 設置調色板
            void CDIB::SetPalette(CPalette* pPal)
            {
                ASSERT(pPal);

                // get the colors from the palette
                int iColors = 0;
                pPal->GetObject(sizeof(iColors), &iColors);
                ASSERT(iColors > 0);
                PALETTEENTRY* pPE = new PALETTEENTRY[iColors];
                pPal->GetPaletteEntries(0, iColors, pPE);

                // Build a table of RGBQUADS
                RGBQUAD* pRGB = new RGBQUAD[iColors];
                ASSERT(pRGB);
                for (int i = 0; i < iColors; i++) {
                    pRGB[i].rgbRed = pPE[i].peRed;
                    pRGB[i].rgbGreen = pPE[i].peGreen;
                    pRGB[i].rgbBlue = pPE[i].peBlue;
                    pRGB[i].rgbReserved = 0;
                }

             SetPalette(0, iColors, pRGB);

                delete [] pRGB;
                delete [] pPE;
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetDC(void)
            //
            // 完成功能:
            //     得到與位圖相關的設備
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    與位圖相關的設備指針
            //
            //////////////////////////////////////////////////////////////////

            //得到與位圖相關的設備
            CDC* CDIB::GetDC(void)
            {
             CDibDC* pdc = new CDibDC;
             if(pdc == NULL)
              return(NULL);
             pdc->CreateCompatibleDC(NULL);
             pdc->m_hOld = (HBITMAP)::SelectObject(pdc->GetSafeHdc(), GetSafeHandle());

             return(pdc);
            }


            //////////////////////////////////////////////////////////////////
            //
            // ReleaseDC(CDC *pdc)
            //
            // 完成功能:
            //     得到與位圖相關的設備
            //
            // 輸入參數:
            //    與位圖相關的設備
            //
            // 返回參數:
            //    是否成功
            //
            //////////////////////////////////////////////////////////////////

            //釋放得到的與位圖相關的設備
            BOOL CDIB::ReleaseDC(CDC *pdc)
            {
             ASSERT(pdc != NULL);
             if(pdc->IsKindOf(RUNTIME_CLASS(CDibDC))){
              delete pdc;
              return(TRUE);
             }
             return(FALSE);
            }

            #ifdef _DEBUG
            void CDIB::Dump(CDumpContext& dc) const
            {
             CGdiObject::Dump(dc);

             if (m_hObject == NULL)
              return;

             BITMAP bm;
             VERIFY(GetObject(sizeof(bm), &bm));
             dc << "bm.bmType = " << bm.bmType;
             dc << "\nbm.bmHeight = " << bm.bmHeight;
             dc << "\nbm.bmWidth = " << bm.bmWidth;
             dc << "\nbm.bmWidthBytes = " << bm.bmWidthBytes;
             dc << "\nbm.bmPlanes = " << bm.bmPlanes;
             dc << "\nbm.bmBitsPixel = " << bm.bmBitsPixel;

             dc << "\n";
            }
            #endif


            //////////////////////////////////////////////////////////////////
            //
            // LoadBmp(LPCSTR filename)
            //
            // 完成功能:
            //     讀入圖像文件
            //
            // 輸入參數:
            //    位圖文件名 filename
            //
            // 返回參數:
            //    是否成功(-1為不成功)
            //
            //////////////////////////////////////////////////////////////////

            //讀入圖像文件
            int CDIB::LoadBmp(LPCSTR filename)
            {
             //打開文件
             CFile file(filename,CFile::modeRead|CFile::shareDenyNone);

             WORD bfType;
             DWORD   bfSize;
             
             //讀入文件頭
             file.Read(&bfType,sizeof(WORD));
             file.Read(&bfSize,sizeof(DWORD));
             if(bfSize <= 0)
             {
              file.Close();
              return -1;
             }
             
             //是否Bmp文件
             if (bfType != (((WORD)'M'<<8) + 'B'))
             {
              file.Close();
              return -1;
             }

             DWORD   bfOffBits;
             //找到位圖數據起始偏移并讀入
             file.Seek(2*sizeof(WORD),CFile::current);
             file.Read(&bfOffBits,sizeof(DWORD));

             LPVOID DibBuf;
             
             DibBuf = (LPVOID)new char[bfSize];

             if(DibBuf == NULL)
             {
              file.Close();
              return -1;
             }

             //讀入位圖數據
             file.ReadHuge(DibBuf,bfSize);
             file.Close();
             
             LPBITMAPINFO pBMI;
             
             int size = bfOffBits - 14;
             pBMI = (LPBITMAPINFO)new char[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];

             //生成信息頭
             memcpy(pBMI,DibBuf,size);
             LPVOID lpBits = (LPVOID)((LPSTR)DibBuf + size);

             //創建位圖
             CreateDIBIndirect(pBMI, lpBits);

             delete pBMI;
             delete DibBuf;
             return 1;
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetColorUsed()
            //
            // 完成功能:
            //     得到使用的顏色數
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    顏色數
            //
            //////////////////////////////////////////////////////////////////

            //得到使用的顏色數
            int CDIB::GetColorUsed()
            {
             LPBITMAPINFOHEADER pBMIH;
             DIBSECTION DibSection;
             GetDibSection(&DibSection);
             pBMIH = &DibSection.dsBmih;
             return pBMIH->biClrUsed;
            }

            //////////////////////////////////////////////////////////////////
            //
            // GetPalette()
            //
            // 完成功能:
            //     得到使用的調色板
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    調色板指針,用完應釋放
            //
            //////////////////////////////////////////////////////////////////

            //得到使用的調色板
            CPalette * CDibDC::GetPalette()
            {
             LOGPALETTE * pLogPal = (LOGPALETTE *)new char[sizeof(LOGPALETTE) +
               256 * sizeof(PALETTEENTRY)];

             pLogPal->palVersion = 0x300;
             pLogPal->palNumEntries = 256;

             HDC hdc = GetSafeHdc();
             RGBQUAD pRGB[256];
             ::GetDIBColorTable(hdc, 0, 256,pRGB);
             
             for(int i = 0 ; i < 256 ; i ++)
             {
              pLogPal->palPalEntry[i].peRed = pRGB[i].rgbRed;
              pLogPal->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
              pLogPal->palPalEntry[i].peBlue = pRGB[i].rgbBlue;
              pLogPal->palPalEntry[i].peFlags = 0;
             }
             
             CPalette * pPal = NULL;
             pPal = new CPalette; 
             pPal->CreatePalette(pLogPal);

             delete pLogPal;
             return pPal;
            }

            //////////////////////////////////////////////////////////////////
            //
            // GetBitmapInfo(void)
            //
            // 完成功能:
            //     得到位圖信息
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    位圖信息指針,用完應釋放
            //
            //////////////////////////////////////////////////////////////////

            //得到位圖信息
            LPBITMAPINFO CDIB::GetBitmapInfo(void)
            {
             DIBSECTION DibSection;
             GetDibSection(&DibSection);
             int nSize = DibSection.dsBmih.biClrUsed*sizeof(RGBQUAD) + sizeof(BITMAPINFOHEADER);
             
             BYTE *pByte = new BYTE[nSize];
             memcpy(pByte, &(DibSection.dsBmih), sizeof(BITMAPINFOHEADER));
             CDC *pdc = GetDC();
             ::GetDIBColorTable(pdc->GetSafeHdc(), 0, DibSection.dsBmih.biClrUsed,
                  (RGBQUAD*)(pByte+sizeof(BITMAPINFOHEADER)));
             ReleaseDC(pdc);
             BITMAPINFO *pBMI = (BITMAPINFO*)pByte;
             return(pBMI);
            }


            //////////////////////////////////////////////////////////////////
            //
            // SaveBmp(LPCSTR filename)
            //
            // 完成功能:
            //     保存位圖文件
            //
            // 輸入參數:
            //    文件名 filename
            //
            // 返回參數:
            //    是否成功
            //
            //////////////////////////////////////////////////////////////////

            //保存文件
            int CDIB::SaveBmp(LPCSTR filename)
            {
             BITMAPFILEHEADER hdr;

             //打開文件
             CFile file(filename,CFile::modeWrite|CFile::modeCreate);

             //文件頭
             hdr.bfType = ((WORD)'M'<<8) + 'B';
             LPBITMAPINFO pbi = GetBitmapInfo();
             PBITMAPINFOHEADER pbih = (PBITMAPINFOHEADER) pbi;

             hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +
                             pbih->biSize + pbih->biClrUsed
                             * sizeof(RGBQUAD) + pbih->biSizeImage);

                hdr.bfReserved1 = 0;
                hdr.bfReserved2 = 0;

                // Compute the offset to the array of color indices.
                hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
                                pbih->biSize + pbih->biClrUsed
                                * sizeof (RGBQUAD);
             
                //寫入文件頭
             file.Write((LPVOID) &hdr, sizeof(BITMAPFILEHEADER));

             //寫入信息頭
                file.Write((LPVOID) pbih, sizeof(BITMAPINFOHEADER)
                              + pbih->biClrUsed * sizeof (RGBQUAD));

                // Copy the array of color indices into the .BMP file.
             //寫入數據
                int nTotal = pbih->biSizeImage;
                LPVOID lpBits = GetBits();
                file.WriteHuge(lpBits, nTotal);

             //關閉文件
             file.Close(); 
             
             delete pbi;

             return 1;
            }


            //////////////////////////////////////////////////////////////////
            //
            // CaptureDIB(CWnd * pWnd, const CRect& capRect)
            //
            // 完成功能:
            //     捕捉窗口圖象
            //
            // 輸入參數:
            //    窗口指針 pWnd
            //     捕捉的大小 capRect
            //
            // 返回參數:
            //    是否成功
            //
            //////////////////////////////////////////////////////////////////

            //捕捉窗口圖象
            BOOL CDIB::CaptureDIB(CWnd * pWnd, const CRect& capRect)
            {
             BOOL ret = false;

             if(pWnd == NULL)
              return false;

             CDC * pPlayDc = pWnd->GetDC();

             if(pPlayDc == NULL)
              return false;

             CRect Rect;
             if(capRect.IsRectEmpty())
              pWnd->GetClientRect(Rect);
             else
              Rect = capRect;

             //得到圖像顏色數
             UINT nBitCount = pPlayDc->GetDeviceCaps(BITSPIXEL);

             //創建位圖
             if(CreateDIB(Rect.Width(), Rect.Height(), nBitCount))
             {
              CDC * pCopyDc = GetDC();
              
              if(pCopyDc == NULL)
              {
               pWnd->ReleaseDC(pPlayDc);  
               return false;
              }

              pWnd->ShowWindow(SW_SHOW);
              //捕捉
              if(pCopyDc->BitBlt(0, 0, Rect.Width(), Rect.Height(), pPlayDc, 0, 0, SRCCOPY))
               ret = true;
              
              ReleaseDC(pCopyDc);
             }

             pWnd->ReleaseDC(pPlayDc);  
             return ret;
            }


            ////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////
            //
            // CDibDC
            //
            // 設備無關位圖設備類(版本1.0)
            //
            // 完成功能:
            //     與設備無關位圖的相關聯
            //
            // 版本所有: 羅雋,曾志
            //
            //////////////////////////////////////////////////////////////////////

            IMPLEMENT_DYNAMIC(CDibDC, CDC);

            CDibDC::CDibDC()
            {
             m_hOld = NULL;
            }

            CDibDC::~CDibDC()
            {
             if(m_hOld != NULL){
              ::SelectObject(GetSafeHdc(), m_hOld);
             }
            }



























            #ifndef __DIB_H
            #define __DIB_H
            //
            // CDIB -
            // CDibDC -
            //
            // Implements a simple encapsulation of a DIB section and a DC.
            //
            //

            //////////////////////////////////////////////////////////////////////
            //
            // CDIB
            //
            // 設備無關位圖類(版本1.0)
            //
            // 完成功能:
            //     設備無關位圖的創建,顯示,讀入,保存,捕捉位圖
            //
            // 版本所有: 羅雋,曾志
            //
            //////////////////////////////////////////////////////////////////////


            class CDIB;
            class CDibDC;

            class CDIB : public CGdiObject
            {
             DECLARE_DYNAMIC(CDIB)

            public:
             //由句柄創建位圖
             static CDIB* PASCAL FromHandle(HBITMAP hBitmap);

            // Constructors
             CDIB();

             //創建位圖
             BOOL CreateDIB(int nWidth, int nHeight, UINT nBitcount, const void* lpBits=NULL);

             //創建位圖
             BOOL CreateDIBIndirect(LPBITMAPINFO lpBitmap, const void* lpBits=NULL);

             //捕捉窗口圖像
             BOOL CaptureDIB(CWnd * pWnd, const CRect& capRect = CRect(0,0,0,0));

            // Attributes
             //得到位圖
             operator HBITMAP() const;

             //拷貝位圖
             CDIB& operator = (CDIB& copy);

            // Operations
             //設置圖像數據
             DWORD SetDIBBits(DWORD dwCount, const void* lpBits);
             //得到圖像數據
             LPVOID GetDIBBits(DWORD dwCount = 0, LPVOID lpBits = NULL);

            // Implementation
            public:
             virtual ~CDIB();
            #ifdef _DEBUG
             virtual void Dump(CDumpContext& dc) const;
            #endif

            // Newly added functions
            public:
             //得到使用的顏色數
             int GetColorUsed();

             //讀入位圖
             int LoadBmp(LPCSTR filename);
             //保存位圖
             int SaveBmp(LPCSTR filename);

             //設置調色板
             void SetPalette(UINT uStartIndex, UINT cEntries, CONST RGBQUAD *pColors);
             //設置調色板
             void SetPalette(CPalette* pPal);
             
             //得到設備
             CDC* GetDC(void);
             //釋放設備
             static BOOL ReleaseDC(CDC *pdc);

             //得到位圖
             int GetBitmap(BITMAP* pBitMap);
             //得到DibSection
             int GetDibSection(DIBSECTION* pDibSection);
             
             //得到寬度
             int GetWidth();
             //得到高度
             int GetHeight();
             //得到尺寸
             SIZE GetSize();
             //得到每行圖像字節數
             int GetWidthBytes();
             //得到圖像位數
             int GetBitCount();
             //得到圖像數據
             LPVOID GetBits();
             //得到圖像信息頭
             LPBITMAPINFO GetBitmapInfo(void);
            };

            ////////////////////////////////////////////////////////////////////
            // inline functions

            //////////////////////////////////////////////////////////////////
            //
            // GetBitmap(BITMAP* pBitMap)
            //
            // 完成功能:
            //     得到位圖
            //
            // 輸入參數:
            //    位圖指針 pBitMap
            //
            // 返回參數:
            //    是否成功
            //
            //////////////////////////////////////////////////////////////////

            //得到位圖
            inline int CDIB::GetBitmap(BITMAP* pBitMap)
            {
             return(::GetObject(m_hObject, sizeof(BITMAP), pBitMap));
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetDibSection(DIBSECTION *pDibSection)
            //
            // 完成功能:
            //     得到DibSection
            //
            // 輸入參數:
            //    DibSection指針 pDibSection
            //
            // 返回參數:
            //    是否成功
            //
            //////////////////////////////////////////////////////////////////

            //得到DibSection
            inline int CDIB::GetDibSection(DIBSECTION *pDibSection)
            {
             return(::GetObject(m_hObject, sizeof(DIBSECTION), pDibSection));
            }


            //////////////////////////////////////////////////////////////////
            //
            // HBITMAP()
            //
            // 完成功能:
            //     得到位圖句柄
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    位圖句柄
            //
            //////////////////////////////////////////////////////////////////

            //得到位圖句柄
            inline CDIB::operator HBITMAP() const
            {
             return (HBITMAP)(this == NULL ? NULL : m_hObject);
            }


            //////////////////////////////////////////////////////////////////
            //
            // FromHandle(HBITMAP hDib)
            //
            // 完成功能:
            //     從位圖句柄得到位圖類
            //
            // 輸入參數:
            //    位圖句柄 hDib
            //
            // 返回參數:
            //    位圖類
            //
            //////////////////////////////////////////////////////////////////

            //從位圖句柄得到位圖類
            inline CDIB* PASCAL CDIB::FromHandle(HBITMAP hDib)
            {
             return((CDIB*)CGdiObject::FromHandle(hDib));
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetWidth(void)
            //
            // 完成功能:
            //     得到寬度
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    寬度
            //
            //////////////////////////////////////////////////////////////////

            //得到寬度
            inline int CDIB::GetWidth(void)
            {
             BITMAP bmp;
             GetBitmap(&bmp);
             return(bmp.bmWidth);
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetHeight(void)
            //
            // 完成功能:
            //     得到高度
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    高度
            //
            //////////////////////////////////////////////////////////////////

            //得到高度
            inline int CDIB::GetHeight(void)
            {
             BITMAP bmp;
             GetBitmap(&bmp);
             return(bmp.bmHeight);
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetSize(void)
            //
            // 完成功能:
            //     得到尺寸
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    尺寸
            //
            //////////////////////////////////////////////////////////////////

            //得到尺寸
            inline SIZE CDIB::GetSize(void)
            {
             BITMAP bmp;
             GetBitmap(&bmp);
             CSize size(bmp.bmWidth, bmp.bmHeight);
             return(size);
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetWidthBytes(void)
            //
            // 完成功能:
            //     得到每行字節數
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    每行字節數
            //
            //////////////////////////////////////////////////////////////////

            //得到每行字節數
            inline int CDIB::GetWidthBytes(void)
            {
             BITMAP bmp;
             GetBitmap(&bmp);
             return(bmp.bmWidthBytes);
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetBitCount(void)
            //
            // 完成功能:
            //     得到圖像位數
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    圖像位數
            //
            //////////////////////////////////////////////////////////////////

            //得到圖像位數
            inline int CDIB::GetBitCount(void)
            {
             BITMAP bmp;
             GetBitmap(&bmp);
             return(bmp.bmBitsPixel);
            }


            //////////////////////////////////////////////////////////////////
            //
            // GetBits(void)
            //
            // 完成功能:
            //     得到圖像數據
            //
            // 輸入參數:
            //    無
            //
            // 返回參數:
            //    圖像數據
            //
            //////////////////////////////////////////////////////////////////

            //得到圖像數據
            inline LPVOID CDIB::GetBits(void)
            {
             BITMAP bmp;
             GetBitmap(&bmp);
             return(bmp.bmBits);
            }

            //////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////
            //
            // CDibDC
            //
            // 設備無關位圖設備類(版本1.0)
            //
            // 完成功能:
            //     與設備無關位圖的相關聯
            //
            // 版本所有: 羅雋,曾志
            //
            //////////////////////////////////////////////////////////////////////


            class CDibDC : public CDC
            {
             DECLARE_DYNAMIC(CDibDC)

            // Constructors
            public:
             CDibDC();

            // Attributes
            protected:
             HBITMAP m_hOld;

            // Implementation
            public:
             CPalette * GetPalette();
             virtual ~CDibDC();
             
             friend class CDIB;
            };

            #endif //__DIB_H

            posted on 2008-09-23 08:20 李帥 閱讀(1916) 評論(1)  編輯 收藏 引用

            評論

            # re: 別人寫的一個位圖操作類CDib 源代碼 2009-11-21 19:32
            能不能把源代碼直接發我郵箱呢,hxf020225@126.com,非常感謝!!!
              回復  更多評論
              

            欧美日韩精品久久免费| 国产日韩欧美久久| 午夜天堂av天堂久久久| 国产欧美久久久精品影院| 91久久婷婷国产综合精品青草| 国产一区二区精品久久| 99久久国产热无码精品免费久久久久| 久久久精品国产Sm最大网站| 久久国产欧美日韩精品免费| 国产精品福利一区二区久久| 久久九九久精品国产免费直播| 亚洲欧美伊人久久综合一区二区| 久久久久久久人妻无码中文字幕爆| 久久精品国产福利国产秒| 色青青草原桃花久久综合| 伊人久久大香线蕉精品| 午夜精品久久久久久久| 青青草原综合久久大伊人导航| 国产精品一久久香蕉国产线看 | 久久久黄色大片| 午夜不卡888久久| AV无码久久久久不卡网站下载 | 国产精品久久久久久久久久影院 | 亚洲国产精品久久| 人妻无码αv中文字幕久久琪琪布| 久久亚洲国产成人影院网站| 青青草原综合久久大伊人精品| 久久婷婷国产综合精品| 久久精品国产久精国产一老狼| 午夜精品久久久久久影视777| 国产成人无码精品久久久久免费| 潮喷大喷水系列无码久久精品| 亚洲精品乱码久久久久久久久久久久 | 91久久九九无码成人网站| 久久精品亚洲中文字幕无码麻豆| 7777精品久久久大香线蕉| 久久久一本精品99久久精品88| 久久久久av无码免费网| 久久伊人精品一区二区三区| 亚洲精品无码久久久影院相关影片 | 久久天天躁狠狠躁夜夜av浪潮|