2004.8.30
9CBS - Technology Community - VC / MFC Graphics Processing / Algorithm
Subject: method without mfc, the image data taken from the dc (do rotation) Author: yuga (Changlaikankan) Grade: credit value: 122 belongs to the community: VC / MFC graphics processing / algorithmic problems Points: 100 Replies : 7 Posted: 2004-8-30 11:25:27
For (int i = 0; i } Layer by layer plotted dcHBITMAP GetSrcBit (HDC hDC, int BitWidth, int BitHeight) {HDC hBufDC; HBITMAP hBitmap, hBitTemp; hBufDC = CreateCompatibleDC (hDC); hBitmap = CreateCompatibleBitmap (hDC, BitWidth, BitHeight); hBitTemp = ( HBITMAP) SelectObject (hBufDC, hBitmap); StretchBlt (hBufDC, 0, 0, bitWidth, BitHeight, hDC, 0, 0, bitWidth, BitHeight, SRCCOPY); hBitmap = (HBITMAP) SelectObject (hBufDC, hBitTemp); DeleteObject (hBitTemp) :: Deletedc (hbufdc); return hbitmap;} Get hbitmapbitmap bm; getObject (hbitmap, sizeof (bm), & bm); this time bm.bmbits is NULL and cannot find bitmap data it corresponds Reply to: lixiaosan (small 3) () Reputation: 140 2004-8-30 11:31:23 Score: 0 http://www.yesky.com/softchannel/723423804681748482_1.shtml Top Reply to: Yuga (Take a look) () Reputation: 122 2004-8-30 11:33:52 Score: 0 MFC is not available, let alone .NET Win32 method Top Reply: Lanstar200 (Maya Brib) () Reputation: 105 2004-8-30 12:54:43 Score: 0 http://community.9cbs.net/expert/faq/faq_index.asp?id=184737 Top Reply: Lanstar200 (Mayan Brillin) () Reputation: 105 2004-8-30 13:00:10 Score: 0 Hbitmap GetSrcbit (HDC HDC, DWORD Bitwidth, DWORD BitHHHT) {Hbitmap Hbitmap, HbitTemp; // Create a device context (HDC) HBUFDC = CREATECOMPALDC (HDC); // Create HBITMAP hBitmap = CreateCompatibleBitmap (hDC, BitWidth, BitHeight); hBitTemp = (HBITMAP) SelectObject (hBufDC, hBitmap); // get bitmap buffer StretchBlt (hBufDC, 0, 0, BitWidth, BitHeight, hDC, 0, 0, BitWidth, BitHHHT, SRCCOPY); // Get the final bitmap information hbitmap = (hbitmap) SelectObject (HBUFDC, HbitTemp); / / Release memory DeleteObject (hbitTemp); :: deletedc (HBUFDC); Return hbitmap; BOOL SaveBMP (HbitMap Hbitmap, LPSTR FileName) {// Device Description Table HDC HDC; // Each pixel per pixel is int ibits; // Bit map 10 Word WbitCount ; / / Define the sliding board size, bitmap pixel byte size, bitmap file size, write file byte DWord dwpalettesize = 0, dwbmbitsize = 0, dwdibsize = 0, dwwritten = 0; // bit map properties Structure Bitmap Bitmap; // Bitmap File Head Structure BitmapFileHeader BMfHDR; // Bitmap Information Head Structure BitmapInfoHeader Bi; / / Pointing Bitmap Information Head Structure LPbitMapInfoHeader LPBI; // Defining File, Assign Handle, Pattern Handle Handle FH , HDIB, HPAL, HOLDPAL = NULL; // Computing bitmap file per pixel number HDC = Createdc ("Display", NULL, NULL, NULL); ibits = getDeviceCaps (HDC, Bitspixel) * getDeDeviceCaps (HDC , Deletedc (HDC); if (iBITS <= 1) wbitcount = 1; ELSE IF (ibits <= 4) wbitcount = 4; Else IF (ibits <= 8) wbitcount = 8; Else Wbitcount = 24; getObject (hBitmap, sizeof (Bitmap), (LPSTR) & Bitmap); bi.biSize = sizeof (BITMAPINFOHEADER); bi.biWidth = Bitmap.bmWidth; bi.biHeight = Bitmap.bmHeight; bi.biPlanes = 1; bi.biBitCount = wBitCount Bi.Bicompression = Bi_RGB; bi.bisizeImage = 0; bi.bixpelspermeter = 0; bi.biypelsper Meter = 0; bi.biclrimportant = 0; bi.biclrused = 0; dwbmbitsSize = ((Bitmap.bmwidth * wbitcount 31) / 32) * 4 * bitmap.bmHeight; // Distributes memory HDIB = GlobalLoc ( GHND, dwBmBitsSize dwPaletteSize sizeof (BITMAPINFOHEADER)); lpbi = (LPBITMAPINFOHEADER) GlobalLock (hDib); * lpbi = bi; // process palette hPal = GetStockObject (DEFAULT_PALETTE); if (hPal) {hDC = :: GetDC (Null); Holdpal = :: SelectPalette (HPALETTE) HPAL, FALSE) ;RIZEPALETTE (HDC); / / Get new pixel values under this palette getDibits (HDC, HBitmap, 0, (UINT) Bitmap.Bmheight, (LPSTR) LPBI Sizeof (BitmapInfoHead) DWPALETESIZE, (BitmapInfo *) lpbi, dib_rgb_colors); // Recovery palette if (Holdpal) {:: SelectPalette (HPALETTPALETTE (HDC, (HPALETTE) HOLDPAL, TRUE); RealizePalette (HDC); :: ReleaseDC (NULL, HDC);} // Create bitmap file fH = createfile (FileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (fh == INVALID_HANDLE_VALUE) return FALSE; // the bitmap file header bmfHdr.bfType = 0x4D42; // "BM" dwDIBSize = sizeof (BITMAPFILEHEADER) sizeof (BITMAPINFOHEADER) dwPaletteSize dwBmBitsSize; bmfHdr.bfSize = dwDIBSize; bmfHdr.bfReserved1 = 0; bmfHdr.bfReserved2 = 0; bmfHdr.bfOffBits = (DWORD) sizeof (BITMAPFILEHEADER) (DWORD) sizeof (BITMAPINFOHEADER) dwPaletteSize; / / Write the bitmap file head Writefile (FH, (LPSTR) & BMFHDR, SIZEOF (BitmapfileHeader), & dwwritten, null); // Write the rest of the content Writefile (FH, (LPSTR) LPBI, DWDIBSIZE, & DWWRITEN, NULL ; // Clear GlobalUnlock (HDIB); Globalf Ree (HDIB); CloseHandle (FH); Return True;} Top Reply to: Yuga (Take a look) () Reputation: 122 2004-8-30 14:46:05 Score: 0 Windows CE GetDibits can't be used for this trouble Top Reply to: Yuga (often come to see) () Reputation: 122 2004-8-30 14:48:19 Score: 0 I am directly drawing data directly on DC GetObject, not BM.BMBITS is empty Top Reply: Linaren (Confused DOTNET) () Reputation: 91 2004-8-30 14:58:04 Score: 0 :) The code upstairs I have seen N times.