2011-10-18 33 views
-2

可能重複:
Save BITMAP C++如何在文件中編寫由程序創建的圖片?

當我學習的C線程編程,我得到一個樣本:

VOID Thread(PVOID pvoid) { 
HBRUSH hBrush; 

HDC hdc; 

int xLeft, xRight, yTop, yBottom, iRed, iGreen, iBlue; 

while (TRUE) { 
    if (cxClient != 0 || cyClient != 0) { 
     Sleep(50); 

     xLeft = rand() % cxClient; 

     xRight = rand() % cxClient; 

     yTop = rand() % cyClient; 

     yBottom = rand() % cyClient; 

     iRed = rand() & 255; 

     iGreen = rand() & 255; 

     iBlue = rand() & 255; 

     hdc = GetDC(hwnd); 

     hBrush = CreateSolidBrush(RGB (iRed, iGreen, iBlue)); 

     SelectObject(hdc, hBrush); 

     Rectangle(hdc, min (xLeft, xRight), min (yTop, yBottom), 
       max (xLeft, xRight), max (yTop, yBottom)); 

     ReleaseDC(hwnd, hdc); 
     DeleteObject(hBrush); 
    } 
} 

}

這個代碼可以創建一些隨機抽取,我想把這些矩形保存到一個文件中,怎麼樣我這樣做?

感謝

+2

我沒有看到艾米C++或線程編程 - 它看起來像Windows C代碼? –

+0

好吧,我只是想知道如何將這些rects保存到一個文件中。順便說一下,這是代碼的一部分 – Neff

回答

0

有沒有內置WINAPI功能這一點。您的選項是:

  1. 寫代碼的文件格式保存您選擇(可能不值得)
  2. 使用第三方一般的圖形庫,如:
    1. Imagemagick
    2. GDI Plus
  3. 使用第三方格式專用庫如libpng
+0

謝謝,我會試試。 – Neff

相關問題