關於記憶體DC

來源:互聯網
上載者:User

      To enable applications to place output in memory rather than sending it to an actual device, use a special device context for bitmap operations called a memory device context. A memory DC enables the system to treat a portion of memory as a virtual device. It is an array of bits in memory that an application can use temporarily to store the color data for bitmaps created on a normal drawing surface. Because the bitmap is compatible with the device, a memory DC is also sometimes referred to as a compatible device context.

     為了能夠讓應用程式在記憶體中而不是在實際裝置中繪圖,使用一種稱作記憶體裝置內容(memory device context)的特殊裝置內容來針對位元影像操作。記憶體DC允許系統分配一部分記憶體來作為虛擬DC,記憶體DC是應用程式可以臨時為在普通繪圖區域建立的位元影像儲存色彩資料而在記憶體中儲存的一系列的位元。由於位元影像和裝置是相容的,所以一個記憶體DC有時也被稱作相容裝置內容。

      The memory DC stores bitmap images for a particular device. An application can create a memory DC by calling the CreateCompatibleDC function.

       記憶體DC為特定的裝置儲存位元影像,一個應用程式可以通過調用CreateCompatibleDC函數建立一個記憶體DC。 關於CreateCompatibleDC函數:

        A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC. To select a bitmap into a DC, use the CreateCompatibleBitmap function, specifying the height, width, and color organization required. 記憶體DC只在記憶體中存在。

        當一個記憶體DC被建立時,它的顯示地區只有一個像素寬一個像素高。在一個應用程式使用記憶體DC進行繪圖操作之前,必須選入一副正確高度和寬度的位元影像到記憶體DC中。為了選入一副位元影像到記憶體DC中,可以使用CreateCompatibleBitmap函數。使用CreateCompatibleBitmap函數,指定所需位元影像的高度,寬度和色彩組織。

        When a memory DC is created, all attributes are set to normal default values. The memory DC can be used as a normal DC. You can set the attributes; obtain the current settings of its attributes; and select pens, brushes, and regions.

        當一個記憶體DC被建立之後,所有的屬性都被設定為預設屬性。記憶體DC可以像普通的DC那樣使用。你可以設定屬性,獲得當前的設定或者當前屬性,並且可以選入筆,畫刷和地區。

         The original bitmap in a memory DC is simply a placeholder. Its dimensions are one pixel by one pixel. Before an application can begin drawing, it must select a bitmap with the appropriate width and height into the DC by calling the SelectObject function. To create a bitmap of the appropriate dimensions, use the CreateBitmap, CreateBitmapIndirect, or CreateCompatibleBitmap function. After the bitmap is selected into the memory DC, the system replaces the single-bit array with an array large enough to store color information for the specified rectangle of pixels.

         記憶體DC中最初的位元影像只是簡單的一個放置場所。它的只有1 x 1大小,在一個應用程式開始繪圖之前,必須通過SelectObject函數選入一個適當高度和寬度大小的位元影像到記憶體DC中。如果想要建立一個合適大小的位元影像,可以使用 CreateBitmap, CreateBitmapIndirect, 或者CreateCompatibleBitmap 函數。當一個位元影像被選入到記憶體DC中,系統會使用能夠儲存特定大小的色多媒體訊息息的足夠大的數組來替換原先單獨位元的數組。

         CreateCompatibleBitmap函數: Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap. To create a color bitmap, use the hDC that was used to create the memory device context, as shown in the following code:

        注意:當一個記憶體DC被建立時,它最初只有一個1X1的單色位元影像在裡面,如果這個記憶體DC被CreateCompatibleBitmap函數使用的話,返回的位元影像就只能是單色的。所以為了建立一個彩色的位元影像,就要使用建立記憶體DC時所使用的hDC來建立。就像以下代碼一樣: HDC memDC = CreateCompatibleDC ( hDC );

         HBITMAP memBM = CreateCompatibleBitmap ( hDC, nWidth, nHeight );//注意這裡的hDC就是建立記憶體DC時使用的DC SelectObject ( memDC, memBM );

        When an application passes the handle returned by CreateCompatibleDC to one of the drawing functions, the requested output does not appear on a device's drawing surface. Instead, the system stores the color information for the resultant line, curve, text, or region in the array of bits. The application can copy the image stored in memory back onto a drawing surface by calling the BitBlt function, identifying the memory DC as the source device context and a window or screen DC as the target device context. 當應用程式把通過CreateCompatibleDC

       函數返回的控制代碼傳遞到繪圖函數中,請求的輸出並不是在裝置的繪圖表面上,相反,系統會把響應的直線,弧線,文本的色多媒體訊息息儲存到記憶體中。應用程式可以使用BitBlt函數從記憶體中把映像複製到一個繪圖表面,把記憶體DC作為源DC,視窗或者螢幕DC作為目標DC。 所有,截取螢幕的代碼應為(在WM_PAINT訊息的處理過程中添加): hdc = BeginPaint(hWnd, &ps); HDC hMemDC; HDC hScreenDC; HBITMAP hBitmap; HBITMAP bitmap; hMemDC=CreateCompatibleDC(hdc); hBitmap=CreateCompatibleBitmap(hdc,1024,768); SelectObject(hMemDC,hBitmap);

//擷取螢幕DC,並且將螢幕DC的內容複寫到記憶體DC中

hScreenDC=GetDC(NULL); BitBlt(hMemDC,0,0,1024,768,hScreenDC,0,0,SRCCOPY);

 //將記憶體DC複製到表單的DC中,在表單中顯示螢幕內容 BitBlt(hdc,0,0,1024,768,hMemDC,0,0,SRCCOPY);

//建立一個相容位元影像來儲存記憶體DC中的映像 hBitmap=CreateCompatibleBitmap(hdc,1024,768); bitmap=(HBITMAP)SelectObject(hMemDC,hBitmap);

//將位元影像放入剪貼簿 OpenClipboard(hWnd); EmptyClipboard();

SetClipboardData(CF_BITMAP,bitmap);

 CloseClipboard(); //釋放DC ReleaseDC(NULL,hScreenDC);

 DeleteDC(hMemDC);

EndPaint(hWnd, &ps);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.