这篇教程C++ GetDIBits函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中GetDIBits函数的典型用法代码示例。如果您正苦于以下问题:C++ GetDIBits函数的具体用法?C++ GetDIBits怎么用?C++ GetDIBits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了GetDIBits函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: CopyScreenToBitmapHBITMAP CopyScreenToBitmap(LPRECT lpRect, BYTE *pData, BITMAPINFO *pHeader){ HDC hScrDC, hMemDC; // screen DC and memory DC HBITMAP hBitmap, hOldBitmap; // handles to deice-dependent bitmaps int nX, nY, nX2, nY2; // coordinates of rectangle to grab int nWidth, nHeight; // DIB width and height int xScrn, yScrn; // screen resolution // check for an empty rectangle if (IsRectEmpty(lpRect)) return NULL; // create a DC for the screen and create // a memory DC compatible to screen DC hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); hMemDC = CreateCompatibleDC(hScrDC); // get points of rectangle to grab nX = lpRect->left; nY = lpRect->top; nX2 = lpRect->right; nY2 = lpRect->bottom; // get screen resolution xScrn = GetDeviceCaps(hScrDC, HORZRES); yScrn = GetDeviceCaps(hScrDC, VERTRES); //make sure bitmap rectangle is visible if (nX < 0) nX = 0; if (nY < 0) nY = 0; if (nX2 > xScrn) nX2 = xScrn; if (nY2 > yScrn) nY2 = yScrn; nWidth = nX2 - nX; nHeight = nY2 - nY; // create a bitmap compatible with the screen DC hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight); // select new bitmap into memory DC hOldBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap); // bitblt screen DC to memory DC BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY); // select old bitmap back into memory DC and get handle to // bitmap of the screen hBitmap = (HBITMAP) SelectObject(hMemDC, hOldBitmap); // Copy the bitmap data into the provided BYTE buffer GetDIBits(hScrDC, hBitmap, 0, nHeight, pData, pHeader, DIB_RGB_COLORS); // clean up DeleteDC(hScrDC); DeleteDC(hMemDC); // return handle to the bitmap return hBitmap;}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:63,
示例2: memsetQPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format){ // Verify size BITMAP bitmap_info; memset(&bitmap_info, 0, sizeof(BITMAP)); int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info); if (!res) { qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info"); return QPixmap(); } int w = bitmap_info.bmWidth; int h = bitmap_info.bmHeight; BITMAPINFO bmi; memset(&bmi, 0, sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = w; bmi.bmiHeader.biHeight = -h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = w * h * 4; QImage result; // Get bitmap bits uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage); HDC display_dc = GetDC(0); if (GetDIBits(display_dc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) { QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied; uint mask = 0; if (format == NoAlpha) { imageFormat = QImage::Format_RGB32; mask = 0xff000000; } // Create image and copy data into image. QImage image(w, h, imageFormat); if (!image.isNull()) { // failed to alloc? int bytes_per_line = w * sizeof(QRgb); for (int y=0; y<h; ++y) { QRgb *dest = (QRgb *) image.scanLine(y); const QRgb *src = (const QRgb *) (data + y * bytes_per_line); for (int x=0; x<w; ++x) { const uint pixel = src[x]; if ((pixel & 0xff000000) == 0 && (pixel & 0x00ffffff) != 0) dest[x] = pixel | 0xff000000; else dest[x] = pixel | mask; } } } result = image; } else { qWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap bits"); } ReleaseDC(0, display_dc); qFree(data); return fromImage(result);}
开发者ID:phen89,项目名称:rtqt,代码行数:62,
示例3: createBMPFilevoid createBMPFile(LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC) { HANDLE hf; // file handle BITMAPFILEHEADER hdr; // bitmap file-header PBITMAPINFOHEADER pbih; // bitmap info-header LPBYTE lpBits; // memory pointer DWORD dwTotal; // total count of bytes DWORD cb; // incremental count of bytes BYTE *hp; // byte pointer DWORD dwTmp; pbih = (PBITMAPINFOHEADER) pbi; lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage); if (!lpBits) throw "Global alloc error"; // Retrieve the color table (RGBQUAD array) and the bits // (array of palette indices) from the DIB. if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, DIB_RGB_COLORS)) { throw "GetDIBits error"; } // Create the .BMP file. hf = CreateFile(pszFile, GENERIC_READ | GENERIC_WRITE, (DWORD) 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); if (hf == INVALID_HANDLE_VALUE) throw "CreateFile error"; hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M" // Compute the size of the entire file. 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); // Copy the BITMAPFILEHEADER into the .BMP file. if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), (LPDWORD) &dwTmp, NULL)) { throw "WriteFile error 1"; } // Copy the BITMAPINFOHEADER and RGBQUAD array into the file. if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD), (LPDWORD) &dwTmp, ( NULL)) ) throw "WriteFile error 2"; // Copy the array of color indices into the .BMP file. dwTotal = cb = pbih->biSizeImage; hp = lpBits; if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL)) throw "WriteFile error 3"; // Close the .BMP file. if (!CloseHandle(hf)) throw "CloseFile error"; // Free memory. GlobalFree((HGLOBAL)lpBits);}
开发者ID:derekqian,项目名称:GPUSim_ATTILA,代码行数:78,
示例4: MFDRV_StretchBltBOOL MFDRV_StretchBlt( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst, INT heightDst, PHYSDEV devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop ){ BOOL ret; DWORD len; METARECORD *mr; BITMAP BM; METAFILEDRV_PDEVICE *physDevSrc = (METAFILEDRV_PDEVICE *)devSrc;#ifdef STRETCH_VIA_DIB LPBITMAPINFOHEADER lpBMI; WORD nBPP;#endif HBITMAP hBitmap = GetCurrentObject(physDevSrc->hdc, OBJ_BITMAP); if (GetObjectW(hBitmap, sizeof(BITMAP), &BM) != sizeof(BITMAP)) { WARN("bad bitmap object %p passed for hdc %p/n", hBitmap, physDevSrc->hdc); return FALSE; }#ifdef STRETCH_VIA_DIB nBPP = BM.bmPlanes * BM.bmBitsPixel; if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */ len = sizeof(METARECORD) + 10 * sizeof(INT16) + sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP: 0) * sizeof(RGBQUAD) + DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight; if (!(mr = HeapAlloc( GetProcessHeap(), 0, len))) return FALSE; mr->rdFunction = META_DIBSTRETCHBLT; lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10); lpBMI->biSize = sizeof(BITMAPINFOHEADER); lpBMI->biWidth = BM.bmWidth; lpBMI->biHeight = BM.bmHeight; lpBMI->biPlanes = 1; lpBMI->biBitCount = nBPP; lpBMI->biSizeImage = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * lpBMI->biHeight; lpBMI->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0; lpBMI->biCompression = BI_RGB; lpBMI->biXPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSX),3937,100); lpBMI->biYPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSY),3937,100); lpBMI->biClrImportant = 0; /* 1 meter = 39.37 inch */ TRACE("MF_StretchBltViaDIB->len = %ld rop=%lx PixYPM=%ld Caps=%d/n", len,rop,lpBMI->biYPelsPerMeter,GetDeviceCaps(physDevSrc->hdc, LOGPIXELSY)); if (GetDIBits(physDevSrc->hdc, hBitmap, 0, (UINT)lpBMI->biHeight, (LPSTR)lpBMI + DIB_BitmapInfoSize( (BITMAPINFO *)lpBMI, DIB_RGB_COLORS ), (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))#else len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight; if (!(mr = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE; mr->rdFunction = META_STRETCHBLT; *(mr->rdParm +10) = BM.bmWidth; *(mr->rdParm +11) = BM.bmHeight; *(mr->rdParm +12) = BM.bmWidthBytes; *(mr->rdParm +13) = BM.bmPlanes; *(mr->rdParm +14) = BM.bmBitsPixel; TRACE("len = %ld rop=%lx/n", len, rop); if (GetBitmapBits( hBitmap, BM.bmWidthBytes * BM.bmHeight, mr->rdParm + 15))#endif { mr->rdSize = len / sizeof(INT16); *(mr->rdParm) = LOWORD(rop); *(mr->rdParm + 1) = HIWORD(rop); *(mr->rdParm + 2) = heightSrc; *(mr->rdParm + 3) = widthSrc; *(mr->rdParm + 4) = ySrc; *(mr->rdParm + 5) = xSrc; *(mr->rdParm + 6) = heightDst; *(mr->rdParm + 7) = widthDst; *(mr->rdParm + 8) = yDst; *(mr->rdParm + 9) = xDst; ret = MFDRV_WriteRecord( devDst, mr, mr->rdSize * 2); } else ret = FALSE; HeapFree( GetProcessHeap(), 0, mr); return ret;}
开发者ID:howard5888,项目名称:wineT,代码行数:81,
示例5: BugDlg_CompressScreenshot//-----------------------------------------------------------------------------// BugDlg_CompressScreenshot//// Compress .BMP to .JPG, Delete .BMP//-----------------------------------------------------------------------------bool BugDlg_CompressScreenshot(){ if ( !g_bug_szScreenshot[0] ) { return false; } bool bSuccess = false; HBITMAP hBitmap = NULL; HDC hDC = NULL; char *pBMPBits = NULL; CUtlBuffer buf( 0, 0 ); hBitmap = (HBITMAP)LoadImage( NULL, g_bug_szScreenshot, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE ); if ( !hBitmap ) goto cleanUp; hDC = CreateCompatibleDC( NULL ); if ( !hDC ) goto cleanUp; BITMAPINFO bitmapInfo; ZeroMemory( &bitmapInfo, sizeof( BITMAPINFO ) ); bitmapInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); // populate the bmp info if ( !GetDIBits( hDC, hBitmap, 0, 0, NULL, &bitmapInfo, DIB_RGB_COLORS ) ) goto cleanUp; pBMPBits = (char *)Sys_Alloc( bitmapInfo.bmiHeader.biSizeImage ); if ( !pBMPBits ) goto cleanUp; // could be bottom-up or top-down int nHeight = abs( bitmapInfo.bmiHeader.biHeight ); if ( bitmapInfo.bmiHeader.biBitCount != 32 ) { // unexpected format goto cleanUp; } if ( bitmapInfo.bmiHeader.biCompression != BI_RGB && bitmapInfo.bmiHeader.biCompression != BI_BITFIELDS ) { // unexpected format goto cleanUp; } // don't want color masks bitmapInfo.bmiHeader.biCompression = BI_RGB; // get the raw bits if ( !GetDIBits( hDC, hBitmap, 0, nHeight, pBMPBits, &bitmapInfo, DIB_RGB_COLORS ) ) goto cleanUp; JSAMPROW row_pointer[1]; // compression data structure struct jpeg_compress_struct cinfo; ZeroMemory( &cinfo, sizeof( jpeg_compress_struct ) ); // point at stderr struct jpeg_error_mgr jerr; cinfo.err = jpeg_std_error( &jerr ); // create compressor jpeg_create_compress( &cinfo ); // Hook CUtlBuffer to compression jpeg_UtlBuffer_dest( &cinfo, &buf ); // image width and height, in pixels cinfo.image_width = bitmapInfo.bmiHeader.biWidth; cinfo.image_height = nHeight; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; // Apply settings jpeg_set_defaults( &cinfo ); jpeg_set_quality( &cinfo, 50, TRUE ); // Start compressor jpeg_start_compress( &cinfo, TRUE); char *pRowBuffer = (char*)_alloca( bitmapInfo.bmiHeader.biWidth * 3 ); row_pointer[0] = (JSAMPROW)pRowBuffer; // Write scanlines while ( cinfo.next_scanline < cinfo.image_height ) { char *pSrc; if ( bitmapInfo.bmiHeader.biHeight < 0 ) { // top down//.........这里部分代码省略.........
开发者ID:DeadZoneLuna,项目名称:SourceEngine2007,代码行数:101,
示例6: GetDesktopWindow//.........这里部分代码省略......... if (fm) { x += 1; } y = topLeftY - textMetric.tmAscent; err = ExtTextOutW(hMemoryDC, x, y, ETO_GLYPH_INDEX|ETO_OPAQUE, (LPRECT)&rect, (LPCWSTR)&glyphCode, 1, NULL); if (err == 0) { FREE_AND_RETURN; } /* Now get the image into a DIB. * MS docs for GetDIBits says the compatible bitmap must not be * selected into a DC, so restore the original first. */ SelectObject(hMemoryDC, hOrigBM); SelectObject(hMemoryDC, oldFont); DeleteObject(hFont); memset(&bmi, 0, sizeof(BITMAPINFO)); bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = -height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biCompression = BI_RGB; dibImage = SAFE_SIZE_ARRAY_ALLOC(malloc, dibBytesWidth, height); if (dibImage == NULL) { FREE_AND_RETURN; } dibImageSize = dibBytesWidth*height; memset(dibImage, 0, dibImageSize); err = GetDIBits(hMemoryDC, hBitmap, 0, height, dibImage, &bmi, DIB_RGB_COLORS); if (err == 0) { /* GetDIBits failed. */ FREE_AND_RETURN; } err = SystemParametersInfo(SPI_GETFONTSMOOTHINGORIENTATION, 0, &orient, 0); if (err == 0) { FREE_AND_RETURN; } err = SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &gamma, 0); if (err == 0) { FREE_AND_RETURN; } igTable = getIGTable(gamma/10); if (igTable == NULL) { FREE_AND_RETURN; } /* Now copy glyph image into a GlyphInfo structure and return it. * NB the xadvance calculated here may be overwritten by the caller. * 1 is subtracted from the bitmap width to get the glyph width, since * that extra "1" was added as padding, so the sub-pixel positioning of * fractional metrics could index into it. */ glyphInfo = (GlyphInfo*)SAFE_SIZE_STRUCT_ALLOC(malloc, sizeof(GlyphInfo), bytesWidth, height); if (glyphInfo == NULL) { FREE_AND_RETURN; } imageSize = bytesWidth*height; glyphInfo->cellInfo = NULL;
开发者ID:sakeinntojiu,项目名称:openjdk8-jdk,代码行数:67,
示例7: winQueryScreenDIBFormatstaticBoolwinQueryScreenDIBFormat (ScreenPtr pScreen, BITMAPINFOHEADER *pbmih){ winScreenPriv(pScreen); HBITMAP hbmp;#if CYGDEBUG LPDWORD pdw = NULL;#endif /* Create a memory bitmap compatible with the screen */ hbmp = CreateCompatibleBitmap (pScreenPriv->hdcScreen, 1, 1); if (hbmp == NULL) { ErrorF ("winQueryScreenDIBFormat - CreateCompatibleBitmap failed/n"); return FALSE; } /* Initialize our bitmap info header */ ZeroMemory (pbmih, sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD)); pbmih->biSize = sizeof (BITMAPINFOHEADER); /* Get the biBitCount */ if (!GetDIBits (pScreenPriv->hdcScreen, hbmp, 0, 1, NULL, (BITMAPINFO*) pbmih, DIB_RGB_COLORS)) { ErrorF ("winQueryScreenDIBFormat - First call to GetDIBits failed/n"); DeleteObject (hbmp); return FALSE; }#if CYGDEBUG /* Get a pointer to bitfields */ pdw = (DWORD*) ((CARD8*)pbmih + sizeof (BITMAPINFOHEADER)); winDebug ("winQueryScreenDIBFormat - First call masks: %08x %08x %08x/n", pdw[0], pdw[1], pdw[2]);#endif /* Get optimal color table, or the optimal bitfields */ if (!GetDIBits (pScreenPriv->hdcScreen, hbmp, 0, 1, NULL, (BITMAPINFO*)pbmih, DIB_RGB_COLORS)) { ErrorF ("winQueryScreenDIBFormat - Second call to GetDIBits " "failed/n"); DeleteObject (hbmp); return FALSE; } /* Free memory */ DeleteObject (hbmp); return TRUE;}
开发者ID:Agnarr,项目名称:xserver,代码行数:62,
示例8: WndProcLRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){ switch( uMsg ) { case WM_COMMAND : switch( LOWORD( wParam ) ) { case IDM_TEST : { BITMAPINFOHEADER bi; BITMAPINFOHEADER* lpbi; HBITMAP hBitmap; HDC hDC, hMemDC; HANDLE hDIB; // Initialize the BITMAPINFOHEADER structure. //........................................... bi.biSize = sizeof( BITMAPINFOHEADER ); bi.biWidth = 50; bi.biHeight = 50; bi.biPlanes = 1; bi.biBitCount = 4; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; hDC = GetDC( hWnd ); // Create DIB. //............ hBitmap = CreateDIBitmap( hDC, &bi, 0L, NULL, NULL, 0 ); // Allocate memory for BITMAPINFO structure. //.......................................... hDIB = GlobalAlloc( GHND, sizeof( BITMAPINFOHEADER )+ 16 * sizeof( RGBQUAD ) ); lpbi = (BITMAPINFOHEADER*)GlobalLock( hDIB ); // Copy bi to top of BITMAPINFO structure. //........................................ *lpbi = bi; // Use GetDIBits() to init bi struct data. //........................................ GetDIBits( hDC, hBitmap, 0, 50, NULL, (LPBITMAPINFO)lpbi, DIB_RGB_COLORS ); GlobalUnlock( hDIB ); // Create a memory device context // and select the DIB into it. //............................... hMemDC = CreateCompatibleDC( hDC ); SelectObject( hMemDC, hBitmap ); // Paint on memory device context. //................................ SelectObject( hMemDC, GetStockObject(BLACK_BRUSH)); Rectangle( hMemDC, 0, 0, 50, 50 ); SelectObject( hMemDC, GetStockObject(WHITE_BRUSH)); Ellipse( hMemDC, 0, 0, 50, 50 ); Ellipse( hMemDC, 10, 0, 40, 50 ); Ellipse( hMemDC, 20, 0, 30, 50 ); // Paint the bitmap on the display. //................................. BitBlt( hDC, 0, 0, 50, 50, hMemDC, 0, 0, SRCCOPY ); DeleteDC( hMemDC ); GlobalFree( hDIB ); ReleaseDC( hWnd, hDC ); } break; case IDM_ABOUT : DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About ); break; case IDM_EXIT : DestroyWindow( hWnd ); break; } break; case WM_DESTROY : PostQuitMessage(0); break; default : return( DefWindowProc( hWnd, uMsg, wParam, lParam ) ); } return( 0L );//.........这里部分代码省略.........
开发者ID:d4nie1,项目名称:TotulDespreCPP,代码行数:101,
示例9: TextProcessorstatic void TextProcessor(INT hdlImage,CHAR *lpText){ BYTE *lp; CHAR szTesto[1024]; POINT pt; IMGHEADER *Img; HDC hDC,hDClone; HBITMAP hbCopy; BYTE *lpSorg; INT iLx,iLy; BITMAPINFOHEADER *BmpHeader; BITMAPINFO *BmpInfo; INT iAlt=12; INT iCol1=0; INT iCol2=-1; BOOL fBold=FALSE; // ---------------------------------------------------------------------------- // Creo una zona di memoria tipo video delle dimensioni dell'immagine // //memcpy(&ImgHeader,memoLock(hdlImage),sizeof(IMGHEADER)); printf("Elaborazione TextProcessor [%s]" CRLF,lpText); //Sleep(2000); //ehLogWrite("> %s" CRLF,lpText); if (!*lpText) return; Img=memoLock(hdlImage); BmpInfo=(BITMAPINFO *) &Img->bmiHeader; BmpHeader=(BITMAPINFOHEADER *) &Img->bmiHeader; iLy=BmpHeader->biHeight; if (iLy<0) iLy=-BmpHeader->biHeight; iLx=BmpHeader->biWidth; hDC=GetDC(NULL); hDClone=CreateCompatibleDC(hDC); SetMapMode(hDClone, MM_TEXT); hbCopy = CreateCompatibleBitmap(hDC, iLx, iLy); SelectObject(hDClone, hbCopy); ReleaseDC(NULL,hDC); lpSorg=(BYTE *) Img; lpSorg+=Img->Offset; // Scrivo l'immagine in questa zona di memoria if (StretchDIBits(hDClone, // Coordinate e dimensioni di stampa a video 0,0, iLx, iLy, // Coordinate e dimensioni di lettura nel sorgente 0, iLy+1, iLx, -iLy, lpSorg, (BITMAPINFO *) &Img->bmiHeader, DIB_RGB_COLORS, SRCCOPY) == GDI_ERROR) {printf("StretchDIBits Failed");} // Ci faccio quello che ci devo fare con i comandi lp=strtok(lpText,"|"); *szTesto=0; ZeroFill(pt); while (lp) { //printf("[%s]" CRLF,lp); if (!memcmp(lp,"TEXT=",5)) strcpy(szTesto,lp+5); if (!memcmp(lp,"PX=",3)) pt.x=atoi(lp+3); if (!memcmp(lp,"PY=",3)) pt.y=atoi(lp+3); if (!memcmp(lp,"ALT=",3)) iAlt=atoi(lp+3); if (!memcmp(lp,"COL=",4)) iCol1=ColorConvert(lp+4); if (!memcmp(lp,"BG=",3)) iCol2=ColorConvert(lp+3); if (!memcmp(lp,"BOLD=",5)) fBold=atoi(lp+5); if (*lp=='*') { //printf("Stampo: %d,%d,%s" CRLF,pt.x,pt.y,szTesto); //ehLogWrite("Stampo: %d,%d,%s",pt.x,pt.y,szTesto); LPrint(hDClone,pt.x,pt.y,iCol1,iCol2,"Arial",iAlt,fBold,szTesto); } lp=strtok(NULL,"|"); } // Mi riprendo la zona di memoria video e la rimetto nell'immagine //BmpHeader->biHeight*=-1; GetDIBits( hDClone, // handle to device context hbCopy, // handle to bitmap 0, // first scan line to set in destination bitmap iLy, // number of scan lines to copy lpSorg, // address of array for bitmap bits (BITMAPINFO *) &Img->bmiHeader, // address of structure with bitmap data DIB_RGB_COLORS // RGB or palette index ); if (!DeleteDC(hDClone)) { ehLogWrite("Errore in cancellazione DC %d",GetLastError()); ehExit("Errore in cancellazione DC"); }//.........这里部分代码省略.........
开发者ID:ferrasrl,项目名称:easyHand,代码行数:101,
示例10: plogpalvoid PLWEMFDecoder::GetImage (PLBmpBase & Bmp){ HPALETTE hpal = NULL; LPLOGPALETTE plogpal (0); if (GetBitsPerPixel() == 8) { plogpal = (LPLOGPALETTE)new PLBYTE[sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256)]; memset(plogpal,0x0,sizeof(LOGPALETTE) + sizeof(PALETTEENTRY)*256); plogpal->palVersion = 0x300; plogpal->palNumEntries = 256; if (plogpal == NULL) { PLASSERT(false); raiseError (PL_ERRNO_MEMORY,"Cannot allocate palette."); } UINT pe = GetEnhMetaFilePaletteEntries(m_hemf, 0, NULL); GetEnhMetaFilePaletteEntries(m_hemf, pe, plogpal->palPalEntry); } // Setup a logical palette for our memory dc and also a // paintlib compatible palette for the paintlib bitmap PLPixel32 pPal[256]; if (plogpal) { for (UINT i = 0; i < 256; i++) { pPal[i] = *(PLPixel32*)&plogpal->palPalEntry[i]; } if ((hpal = CreatePalette((LPLOGPALETTE)plogpal))) { m_holdpal = SelectPalette(m_memdc, hpal, false); RealizePalette(m_memdc); } Bmp.SetPalette(pPal); delete [] plogpal; } // Play the metafile into the device context // First, setup a bounding rectangle and fill // the memory dc with white (some metafiles only // use a black pen to draw and have no actual fill // color set, This would cause a black on black // painting which is rather useless RECT rc; rc.left = rc.top = 0; rc.bottom = GetHeight(); rc.right = GetWidth(); FillRect(m_memdc,&rc,(HBRUSH)GetStockObject(WHITE_BRUSH)); // Heeere we go.... BOOL bres = PlayEnhMetaFile(m_memdc,m_hemf,&rc); // Finally, convert the Windows bitmap into a paintlib bitmap PLWinBmp& winbmp = dynamic_cast<PLWinBmp&>(Bmp); BITMAPINFO* pBMI = (BITMAPINFO*)winbmp.GetBMI(); PLBYTE* pBits = (PLBYTE*)winbmp.GetBits(); if (GetBitsPerPixel() == 8) { GetDIBits(m_dc, m_bm, 0, GetHeight(), winbmp.GetBits(), pBMI, DIB_RGB_COLORS); } else { GetDIBits(m_dc, m_bm, 0, GetHeight(), winbmp.GetBits(), pBMI, DIB_PAL_COLORS); }}
开发者ID:JesperMikkelsen,项目名称:Big-Numbers,代码行数:61,
示例11: CxImage//////////////////////////////////////////////////////////////////////////////// CMainFrame message handlersvoid CMainFrame::OnEditPaste() { CDemoDoc *NewDoc=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL); if (NewDoc) { if (OpenClipboard()) { HANDLE hData=NULL; if (hData = GetClipboardData(((CDemoApp*)AfxGetApp())->GetCF())){ //custom CxImage object CxImage *newima = new CxImage(); DWORD dwSize = GlobalSize(hData); if (dwSize) { BYTE *lpVoid = (BYTE *)GlobalLock(hData); newima->UnDump(lpVoid); GlobalUnlock(lpVoid); } NewDoc->image = newima; } else if (hData = GetClipboardData(CF_DIB)){ // check if bitmap CxImage *newima = new CxImage(); newima->CreateFromHANDLE(hData); NewDoc->image = newima; } else { #if CXIMAGE_SUPPORT_WMF if (hData = GetClipboardData(CF_ENHMETAFILE)) //check if metafile { HENHMETAFILE hMeta = (HENHMETAFILE)hData; ENHMETAHEADER emh; GetEnhMetaFileHeader(hMeta, sizeof(emh), &emh); int cx,cy; cx = (int)((emh.rclBounds.right - emh.rclBounds.left)/2.54); cy = (int)((emh.rclBounds.bottom - emh.rclBounds.top)/2.54); HDC hDC0 = ::GetDC(0); // screen dc HBITMAP hBitmap = CreateCompatibleBitmap(hDC0, cx, cy); HDC hDC = CreateCompatibleDC(hDC0); // memory dc compatible with screen ::ReleaseDC(0, hDC0); // don't need anymore. get rid of it. if (hDC && hBitmap){ RECT rc = {0,0,cx,cy}; int bpp = ::GetDeviceCaps(hDC, BITSPIXEL); HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap); // paint the background DWORD dwBack = RGB(255, 255, 255); //GetSysColor(COLOR_WINDOW); DWORD OldColor = SetBkColor(hDC, dwBack); ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); SetBkColor(hDC, OldColor); // Play the Metafile into Memory DC BOOL bRet = PlayEnhMetaFile(hDC, hMeta, &rc); SelectObject(hDC, hBitmapOld); CxImage *newima = new CxImage(); if(bRet && newima->Create(cx, cy, bpp, CXIMAGE_FORMAT_WMF)){ bRet = GetDIBits(hDC, hBitmap, 0, (UINT)cy, newima->GetBits(), (LPBITMAPINFO)newima->GetDIB(), DIB_RGB_COLORS); NewDoc->image = newima; } else { delete newima; } } if (hBitmap) DeleteObject(hBitmap); if (hDC) DeleteDC(hDC); }#endif } } CloseClipboard(); CString s; s.Format(_T("Clipboard Image %d"),((CDemoApp*)AfxGetApp())->m_nDocCount++); NewDoc->SetTitle(s); NewDoc->UpdateAllViews(0,WM_USER_NEWIMAGE); NewDoc->UpdateStatusBar(); }}
开发者ID:Aliceljm1,项目名称:CxImageVS2010,代码行数:89,
示例12: HDumpGraf/* EXPORT->HDumpGraf: dump a BMP image of current display into fname */void HDumpGraf(char *fname){ BITMAPFILEHEADER FileHeader; BITMAPINFOHEADER BitmapHeader; BITMAPINFO *Info; int ColorTableSize; int ImageSize; FILE *fp; char *img; HDC dc = GetDC(theWindow); HBITMAP temp = CreateCompatibleBitmap(memDC,1,1); SelectObject(memDC,temp); /* retrieve information about the bitmap */ BitmapHeader.biSize = sizeof(BITMAPINFOHEADER); BitmapHeader.biBitCount = 0; GetDIBits(memDC,theBitmap,0,0,NULL,&BitmapHeader,BI_RGB); switch (BitmapHeader.biCompression) { case BI_RGB: if (BitmapHeader.biBitCount > 8) { ColorTableSize = 0; } else { ColorTableSize = BitmapHeader.biClrUsed*sizeof(RGBQUAD); } break; case BI_RLE8: case BI_RLE4: ColorTableSize = BitmapHeader.biClrUsed*sizeof(RGBQUAD); break; case BI_BITFIELDS: ColorTableSize = 3*sizeof(DWORD); } Info = (BITMAPINFO *) New(&gcheap,sizeof(BITMAPINFOHEADER) + ColorTableSize); memcpy(Info,&BitmapHeader,sizeof(BITMAPINFOHEADER)); ImageSize = BitmapHeader.biSizeImage; img = New(&gcheap,ImageSize); GetDIBits(memDC,theBitmap,0,ClientRect.bottom,img,Info,BI_RGB); FileHeader.bfType = 0x4d42; /* 'BM' */ FileHeader.bfSize = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER) + ImageSize + ColorTableSize; FileHeader.bfReserved1 = FileHeader.bfReserved2 = 0; FileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + ColorTableSize; fp = fopen(fname,"wb"); fwrite(&FileHeader,1,sizeof(BITMAPFILEHEADER),fp); fwrite(Info,1,sizeof(BITMAPINFOHEADER) + ColorTableSize,fp); fwrite(img,1,ImageSize,fp); fclose(fp); SelectObject(memDC,theBitmap); DeleteObject(temp); Dispose(&gcheap,Info); Dispose(&gcheap,img);}
开发者ID:botonchou,项目名称:AlgoFinal,代码行数:62,
示例13: sizeofHBITMAP MonitorImageSource::GetImage(int width, int height){ DISPLAY_DEVICE named_device; named_device.cb = sizeof(DISPLAY_DEVICE); for (int deviceId = 0;;deviceId++) { DISPLAY_DEVICE device; device.cb = sizeof(DISPLAY_DEVICE); BOOL result = ::EnumDisplayDevices(NULL, deviceId, &device, 0); if (result == 0) break; if (device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) { result = ::EnumDisplayDevices(device.DeviceName, 0, &named_device, 0); } } HBITMAP hbmScreen = NULL; BITMAP bmpScreen; // Retrieve the handle to a display device context for the client // area of the window. Win32::DisplayDeviceContext hdcScreen("DISPLAY"); Win32::WindowDeviceContext hdcWindow(::GetDesktopWindow()); // Create a compatible DC which is used in a BitBlt from the window DC Win32::MemoryDeviceContext hdcMemDC(hdcWindow); //This is the best stretch mode ::SetStretchBltMode(hdcWindow,HALFTONE); //The source DC is the entire screen and the destination DC is the current window (HWND) if(!::StretchBlt(hdcWindow, 0,0, width, height, hdcScreen, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN), SRCCOPY)) { } // Create a compatible bitmap from the Window DC hbmScreen = CreateCompatibleBitmap(hdcWindow, width, height); if(!hbmScreen) { //TODO: Error handling } // Select the compatible bitmap into the compatible memory DC. SelectObject(hdcMemDC,hbmScreen); // Bit block transfer into our compatible memory DC. if(!BitBlt(hdcMemDC, 0,0, width, height, hdcWindow, 0,0, SRCCOPY)) { //TODO: Error handling } // Get the BITMAP from the HBITMAP GetObject(hbmScreen,sizeof(BITMAP),&bmpScreen); BITMAPFILEHEADER bmfHeader; BITMAPINFOHEADER bi; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bmpScreen.bmWidth; bi.biHeight = bmpScreen.bmHeight; bi.biPlanes = 1; bi.biBitCount = 32; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight; // Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc // have greater overhead than HeapAlloc. HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); char *lpbitmap = (char *)GlobalLock(hDIB); // Gets the "bits" from the bitmap and copies them into a buffer // which is pointed to by lpbitmap. GetDIBits(hdcWindow, hbmScreen, 0, (UINT)bmpScreen.bmHeight, lpbitmap, (BITMAPINFO *)&bi, DIB_RGB_COLORS); // A file is created, this is where we will save the screen capture. HANDLE hFile = CreateFile(L"captureqwsx.bmp", GENERIC_WRITE, 0, NULL,//.........这里部分代码省略.........
开发者ID:bstewart00,项目名称:remote-screen,代码行数:101,
示例14: fbx_initint fbx_init(fbx_struct *fb, fbx_wh wh, int width_, int height_, int useShm){ int width, height; int rmask, gmask, bmask, ps, i; #ifdef _WIN32 BMINFO bminfo; HBITMAP hmembmp=0; RECT rect; HDC hdc=NULL; #else XWindowAttributes xwa; int shmok=1, alphaFirst, pixmap=0; #endif if(!fb) _throw("Invalid argument"); #ifdef _WIN32 if(!wh) _throw("Invalid argument"); _w32(GetClientRect(wh, &rect)); if(width_>0) width=width_; else { width=rect.right-rect.left; if(width<=0) width=MINWIDTH; } if(height_>0) height=height_; else { height=rect.bottom-rect.top; if(height<=0) height=MINHEIGHT; } if(fb->wh==wh) { if(width==fb->width && height==fb->height && fb->hmdc && fb->hdib && fb->bits) return 0; else if(fbx_term(fb)==-1) return -1; } memset(fb, 0, sizeof(fbx_struct)); fb->wh=wh; _w32(hdc=GetDC(fb->wh)); _w32(fb->hmdc=CreateCompatibleDC(hdc)); _w32(hmembmp=CreateCompatibleBitmap(hdc, width, height)); _w32(GetDeviceCaps(hdc, RASTERCAPS)&RC_BITBLT); _w32(GetDeviceCaps(fb->hmdc, RASTERCAPS)&RC_DI_BITMAP); bminfo.bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); bminfo.bmi.bmiHeader.biBitCount=0; _w32(GetDIBits(fb->hmdc, hmembmp, 0, 1, NULL, &bminfo.bmi, DIB_RGB_COLORS)); _w32(GetDIBits(fb->hmdc, hmembmp, 0, 1, NULL, &bminfo.bmi, DIB_RGB_COLORS)); _w32(DeleteObject(hmembmp)); hmembmp=0; /* (we only needed it to get the screen properties) */ ps=bminfo.bmi.bmiHeader.biBitCount/8; if(width>0) bminfo.bmi.bmiHeader.biWidth=width; if(height>0) bminfo.bmi.bmiHeader.biHeight=height; fb->width=bminfo.bmi.bmiHeader.biWidth; fb->height=bminfo.bmi.bmiHeader.biHeight; if(ps<3) { /* Make the buffer BGRA */ bminfo.bmi.bmiHeader.biCompression=BI_BITFIELDS; bminfo.bmi.bmiHeader.biBitCount=32; ps=4; (*(DWORD *)&bminfo.bmi.bmiColors[0])=0xFF0000; (*(DWORD *)&bminfo.bmi.bmiColors[1])=0xFF00; (*(DWORD *)&bminfo.bmi.bmiColors[2])=0xFF; } fb->pitch=BMPPAD(fb->width*ps); /* Windoze bitmaps are always padded */ if(bminfo.bmi.bmiHeader.biCompression==BI_BITFIELDS) { rmask=(*(DWORD *)&bminfo.bmi.bmiColors[0]); gmask=(*(DWORD *)&bminfo.bmi.bmiColors[1]); bmask=(*(DWORD *)&bminfo.bmi.bmiColors[2]); } else { rmask=0xFF0000; gmask=0xFF00; bmask=0xFF; } fb->format=-1; for(i=0; i<FBX_FORMATS; i++) if(rmask==fbx_rmask[i] && gmask==fbx_gmask[i] && bmask==fbx_bmask[i] && ps==fbx_ps[i] && fbx_alphafirst[i]==0) fb->format=i; if(fb->format==-1) _throw("Display has unsupported pixel format"); bminfo.bmi.bmiHeader.biHeight=-bminfo.bmi.bmiHeader.biHeight; /* (our convention is top-down) */ _w32(fb->hdib=CreateDIBSection(hdc, &bminfo.bmi, DIB_RGB_COLORS, (void **)&fb->bits, NULL, 0)); _w32(SelectObject(fb->hmdc, fb->hdib)); ReleaseDC(fb->wh, hdc); return 0; finally: if(hmembmp) DeleteObject(hmembmp); if(hdc) ReleaseDC(fb->wh, hdc); #else if(!wh.dpy || !wh.d) _throw("Invalid argument");//.........这里部分代码省略.........
开发者ID:coffee8651,项目名称:turbovnc,代码行数:101,
示例15: takescreenshot/* Takes a screenshot of the screen and saves it in memory*/int takescreenshot(unsigned char **screenshotbuffer,int *screenshotbuffersize){ //declaring & initializing needed vars HDC screendc = NULL; HDC compatiblescreendc = NULL; HBITMAP compatiblebitmap = NULL; HGDIOBJ selectedobject = NULL; BOOL bitbltresult = FALSE; int getobjectresult = 0; BITMAP finalbmp = {0}; BITMAPFILEHEADER bmfileheader = {0}; BITMAPINFOHEADER bminfoheader = {0}; DWORD dwBmpSize = 0; HANDLE hDIB = NULL; unsigned char *lpbitmap = NULL; int getdibitsresult = 0; DWORD dwSizeofDIB = 0; int screenwidth = 0; int screenheight = 0; int leftxscreenpos = 0; int leftyscreenpos = 0; char currentpath[MAX_PATH] = {0}; //left side virtual screen coordinates leftxscreenpos = GetSystemMetrics(SM_XVIRTUALSCREEN); //top side virtual screen coordinates leftyscreenpos = GetSystemMetrics(SM_YVIRTUALSCREEN); //width in pixels of the virtual screen screenwidth = GetSystemMetrics(SM_CXVIRTUALSCREEN); //height in pixels of the virtual screen screenheight = GetSystemMetrics(SM_CYVIRTUALSCREEN); /*actually take the screenshot*/ screendc = GetDC(NULL); if(screendc == NULL){ outputerror(DBG_ERROR,"%s/n","takescreenshot::GetDC() Failed"); return 1; } compatiblescreendc = CreateCompatibleDC(screendc); if(compatiblescreendc == NULL){ outputerror(DBG_ERROR,"%s/n","takescreenshot::CreateCompatibleDC() Failed"); ReleaseDC(NULL,screendc); return 1; } compatiblebitmap = CreateCompatibleBitmap(screendc,screenwidth,screenheight); if(compatiblebitmap == NULL){ outputerror(DBG_ERROR,"%s/n","takescreenshot::CreateCompatibleBitmap() Failed"); ReleaseDC(NULL,screendc); DeleteDC(compatiblescreendc); return 1; } selectedobject = SelectObject(compatiblescreendc,compatiblebitmap); if(selectedobject == NULL || selectedobject == HGDI_ERROR){ outputerror(DBG_ERROR,"%s/n","takescreenshot::SelectObject() Failed"); ReleaseDC(NULL,screendc); DeleteDC(compatiblescreendc); DeleteObject(compatiblebitmap); return 1; } bitbltresult = BitBlt(compatiblescreendc,0,0,screenwidth,screenheight,screendc,leftxscreenpos,leftyscreenpos,SRCCOPY); if(bitbltresult == 0){ outputerror(DBG_ERROR,"%s %d/n","takescreenshot::BitBlt() Failed", GetLastError()); ReleaseDC(NULL,screendc); DeleteDC(compatiblescreendc); DeleteObject(compatiblebitmap); return 1; } /*save the screenshot to file*/ getobjectresult = GetObject(compatiblebitmap,sizeof(BITMAP),&finalbmp); if(getobjectresult == 0){ outputerror(DBG_ERROR,"%s/n","takescreenshot::GetObject() Failed"); ReleaseDC(NULL,screendc); DeleteDC(compatiblescreendc); DeleteObject(compatiblebitmap); return 1; } //bmp file format good read: http://en.wikipedia.org/wiki/BMP_file_format bminfoheader.biSize = sizeof(BITMAPINFOHEADER); bminfoheader.biWidth = screenwidth; bminfoheader.biHeight = screenheight; bminfoheader.biPlanes = 1; bminfoheader.biBitCount = 32; bminfoheader.biCompression = BI_RGB; bminfoheader.biSizeImage = 0; bminfoheader.biXPelsPerMeter = 0; bminfoheader.biYPelsPerMeter = 0; bminfoheader.biClrUsed = 0; bminfoheader.biClrImportant = 0; dwBmpSize = ((screenwidth * bminfoheader.biBitCount + 31) / 32) * 4 * screenheight; hDIB = GlobalAlloc(GHND,dwBmpSize); lpbitmap = (unsigned char *)GlobalLock(hDIB); //get the actual bitmap 'bits' getdibitsresult = GetDIBits(compatiblescreendc, compatiblebitmap, 0,(UINT)finalbmp.bmHeight, lpbitmap, (BITMAPINFO *)&bminfoheader, DIB_RGB_COLORS); if(getdibitsresult == 0){ outputerror(DBG_ERROR,"%s/n","takescreenshot::GetDIBits() Failed"); ReleaseDC(NULL,screendc);//.........这里部分代码省略.........
开发者ID:DiabloHorn,项目名称:cryptoshot,代码行数:101,
示例16: sizeofstatic fz_image *render_to_pixmap(fz_context *ctx, HBITMAP hbmp, SizeI size){ int w = size.dx, h = size.dy; int stride = ((w * 3 + 3) / 4) * 4; unsigned char *data = (unsigned char *)fz_malloc(ctx, stride * h); BITMAPINFO bmi = { 0 }; bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = w; bmi.bmiHeader.biHeight = -h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biCompression = BI_RGB; HDC hDC = GetDC(nullptr); int res = GetDIBits(hDC, hbmp, 0, h, data, &bmi, DIB_RGB_COLORS); ReleaseDC(nullptr, hDC); if (!res) { fz_free(ctx, data); fz_throw(ctx, FZ_ERROR_GENERIC, "GetDIBits failed"); } // convert BGR with padding to RGB without padding unsigned char *out = data; bool is_grayscale = true; for (int y = 0; y < h; y++) { const unsigned char *in = data + y * stride; unsigned char green, blue; for (int x = 0; x < w; x++) { is_grayscale = is_grayscale && in[0] == in[1] && in[0] == in[2]; blue = *in++; green = *in++; *out++ = *in++; *out++ = green; *out++ = blue; } } // convert grayscale RGB to proper grayscale if (is_grayscale) { const unsigned char *in = out = data; for (int i = 0; i < w * h; i++) { *out++ = *in++; in += 2; } } fz_compressed_buffer *buf = nullptr; fz_var(buf); fz_try(ctx) { buf = fz_malloc_struct(ctx, fz_compressed_buffer); buf->buffer = fz_new_buffer(ctx, w * h * 4 + 10); buf->params.type = FZ_IMAGE_FLATE; buf->params.u.flate.predictor = 1; z_stream zstm = { 0 }; zstm.next_in = data; zstm.avail_in = out - data; zstm.next_out = buf->buffer->data; zstm.avail_out = buf->buffer->cap; res = deflateInit(&zstm, 9); if (res != Z_OK) fz_throw(ctx, FZ_ERROR_GENERIC, "deflate failure %d", res); res = deflate(&zstm, Z_FINISH); if (res != Z_STREAM_END) fz_throw(ctx, FZ_ERROR_GENERIC, "deflate failure %d", res); buf->buffer->len = zstm.total_out; res = deflateEnd(&zstm); if (res != Z_OK) fz_throw(ctx, FZ_ERROR_GENERIC, "deflate failure %d", res); } fz_always(ctx) { fz_free(ctx, data); } fz_catch(ctx) { fz_free_compressed_buffer(ctx, buf); fz_rethrow(ctx); } fz_colorspace *cs = is_grayscale ? fz_device_gray(ctx) : fz_device_rgb(ctx); return fz_new_image(ctx, w, h, 8, cs, 96, 96, 0, 0, nullptr, nullptr, buf, nullptr);}
开发者ID:eottone,项目名称:sumatrapdf,代码行数:84,
示例17: ConvertWmfFiletoEmf//.........这里部分代码省略......... HDC hDC0 = GetDC(0); // DC of screen HBITMAP hBitmap = CreateCompatibleBitmap(hDC0, cx, cy); // has # colors of display hDC = CreateCompatibleDC(hDC0); // memory dc compatible with screen ReleaseDC(0, hDC0); // don't need anymore. get rid of it. if (hDC){ if (hBitmap){ RECT rc = {0,0,cx,cy}; int bpp = ::GetDeviceCaps(hDC, BITSPIXEL); HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap); // clear out the entire bitmap with windows background // because the MetaFile may not contain background information DWORD dwBack = XMF_COLOR_BACK;#if XMF_SUPPORT_TRANSPARENCY if (bpp == 24) dwBack = XMF_COLOR_TRANSPARENT;#endif DWORD OldColor = SetBkColor(hDC, dwBack); ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); SetBkColor(hDC, OldColor); //retrieves optional palette entries from the specified enhanced metafile PLOGPALETTE plogPal; PBYTE pjTmp; HPALETTE hPal; int iEntries = GetEnhMetaFilePaletteEntries(hMeta, 0, NULL); if (iEntries) { if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(DWORD) + sizeof(PALETTEENTRY)*iEntries )) == NULL) { DeleteObject(hBitmap); DeleteDC(hDC); DeleteEnhMetaFile(hMeta); strcpy(info.szLastError,"Cancelled"); return false; } plogPal->palVersion = 0x300; plogPal->palNumEntries = (WORD) iEntries; pjTmp = (PBYTE) plogPal; pjTmp += 4; GetEnhMetaFilePaletteEntries(hMeta, iEntries, (PPALETTEENTRY)pjTmp); hPal = CreatePalette(plogPal); GlobalFree(plogPal); SelectPalette(hDC, hPal, FALSE); RealizePalette(hDC); } // Play the Metafile into Memory DC BOOL bRet = PlayEnhMetaFile(hDC, // handle to a device context hMeta, // handle to an enhanced metafile &rc); // pointer to bounding rectangle SelectObject(hDC, hBitmapOld); DeleteEnhMetaFile(hMeta); // we are done with this one if (info.nEscape) { // Check if cancelled DeleteObject(hBitmap); DeleteDC(hDC); strcpy(info.szLastError,"Cancelled"); return false; } // the Bitmap now has the image. // Create our DIB and convert the DDB into DIB if (!Create(cx, cy, bpp, CXIMAGE_FORMAT_WMF)) { DeleteObject(hBitmap); DeleteDC(hDC); return false; }#if XMF_SUPPORT_TRANSPARENCY if (bpp == 24) { RGBQUAD rgbTrans = { XMF_RGBQUAD_TRANSPARENT }; SetTransColor(rgbTrans); }#endif // We're finally ready to get the DIB. Call the driver and let // it party on our bitmap. It will fill in the color table, // and bitmap bits of our global memory block. bRet = GetDIBits(hDC, hBitmap, 0, (UINT)cy, GetBits(), (LPBITMAPINFO)pDib, DIB_RGB_COLORS); DeleteObject(hBitmap); DeleteDC(hDC); return (bRet!=0); } else { DeleteDC(hDC); } } else { if (hBitmap) DeleteObject(hBitmap); } DeleteEnhMetaFile(hMeta); return false;}
开发者ID:Brukwa,项目名称:VisualBoyAdvance,代码行数:101,
示例18: CreateBMPFileBOOL CreateBMPFile(const char *szFile, HBITMAP hBMP) { // Saves the hBitmap as a bitmap. HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); HDC hdcCompatible = CreateCompatibleDC(hdcScreen); PBITMAPINFO pbmi=NULL; BOOL bret=FALSE; HANDLE hf=NULL; // file handle BITMAPFILEHEADER hdr; // bitmap file-header PBITMAPINFOHEADER pbih=NULL; // bitmap info-header LPBYTE lpBits=NULL; // memory pointer DWORD dwTotal=0; // total count of bytes DWORD cb=0; // incremental count of bytes BYTE *hp=NULL; // byte pointer DWORD dwTmp=0; BITMAP bmp; memset(&bmp,0,sizeof(BITMAP)); GetObject(hBMP,sizeof(BITMAP),&bmp); memset(&hdr,0,sizeof(hdr)); { int cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel); if (cClrBits>8) { // No Palette (normally) pbmi = (PBITMAPINFO) calloc(1, sizeof(BITMAPINFOHEADER)); } else { pbmi = (PBITMAPINFO) calloc(1, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (1<<(min(8,cClrBits)))); pbmi->bmiHeader.biClrUsed = (1<<cClrBits); } // Initialize the fields in the BITMAPINFO structure. pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); // Retrieve the color table (RGBQUAD array) and the bits // (array of palette indices) from the DIB. if (!GetDIBits(hdcCompatible, hBMP, 0, bmp.bmHeight, NULL, pbmi, DIB_RGB_COLORS)) { goto to_return; } } pbih = &(pbmi->bmiHeader); pbmi->bmiHeader.biCompression=BI_RGB; lpBits = (LPBYTE) calloc(1, pbih->biSizeImage); if (!lpBits) { goto to_return; } if (!GetDIBits(hdcCompatible, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbmi, DIB_RGB_COLORS)) { goto to_return; } // Create the .BMP file. hf = CreateFile(szFile, GENERIC_READ | GENERIC_WRITE, (DWORD) 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); if (hf == INVALID_HANDLE_VALUE) { goto to_return; } hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M" // Compute the size of the entire file. 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); // Copy the BITMAPFILEHEADER into the .BMP file. if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), (LPDWORD) &dwTmp, NULL)) { goto to_return; } // Copy the BITMAPINFOHEADER and RGBQUAD array into the file. if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD), (LPDWORD) &dwTmp, ( NULL))) { goto to_return; } // Copy the array of color indices into the .BMP file. dwTotal = cb = pbih->biSizeImage; hp = lpBits; if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL)) { goto to_return; } // Close the .BMP file. if (!CloseHandle(hf)) { goto to_return; } bret=TRUE; to_return:; // Free memory. if(pbmi)free(pbmi); if(lpBits)free(lpBits); DeleteDC(hdcCompatible); DeleteDC(hdcScreen); return bret;}
开发者ID:buranela,项目名称:OpenHoldemV12,代码行数:93,
示例19: CreateCompatibleDC//.........这里部分代码省略......... m_KerningPairs.Add(TKerningPair((char) pKernPairs[i].wFirst, (char) pKernPairs[i].wSecond, pKernPairs[i].iKernAmount)); delete [] pKernPairs; fRows = sqrt(iChars * m_iMaxWidth / (float) m_iHeight); fCols = fRows * m_iHeight / (float) m_iMaxWidth; m_iCellCols = (int) ceil(fCols); m_iCellRows = (int) ceil(fRows); if (m_iCellCols > m_iCellRows) { if (m_iCellCols * (m_iCellRows - 1) >= iChars) m_iCellRows--; } else if ((m_iCellCols - 1) * m_iCellRows >= iChars) m_iCellCols--; ASSERT(m_iCellRows * m_iCellCols >= iChars); BITMAPINFO bmi; bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = m_iCellCols * m_iMaxWidth; bmi.bmiHeader.biHeight = -m_iCellRows * m_iHeight; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = (int) (iXdpi / 2.54f * 100); bmi.bmiHeader.biYPelsPerMeter = (int) (iYdpi / 2.54f * 100); bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; HBITMAP hBmp = CreateDIBSection(hDC, &bmi, 0, 0, 0, 0); SelectObject(hDC, hBmp); HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0)); SelectObject(hDC, hBrush); Rectangle(hDC, 0, 0, m_iCellCols * m_iMaxWidth, m_iCellRows * m_iHeight); SetTextColor(hDC, RGB(255, 255, 255)); SetBkColor(hDC, RGB(0, 0, 0)); SetBkMode(hDC, TRANSPARENT); SetTextAlign(hDC, TA_TOP | TA_LEFT | TA_NOUPDATECP); for (int iRow = 0; iRow < m_iCellRows; iRow++) for (int iCol = 0; iCol < m_iCellCols; iCol++) { RECT rc; char chBuf[2] = { m_iFirstChar + iRow * m_iCellCols + iCol, 0 }; if (!m_Chars[(uint8_t) chBuf[0]].ch) continue; rc.left = iCol * m_iMaxWidth - m_Chars[(uint8_t) chBuf[0]].iA; rc.top = iRow * m_iHeight; rc.right = rc.left + m_iMaxWidth; rc.bottom = rc.top + m_iHeight;// DrawText(hDC, chBuf, 1, &rc, DT_LEFT | DT_TOP); TextOut(hDC, rc.left, rc.top, chBuf, 1); } bRes = !!GdiFlush(); bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = m_iCellCols * m_iMaxWidth; bmi.bmiHeader.biHeight = -m_iCellRows * m_iHeight; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = (int) (iXdpi / 2.54f * 100); bmi.bmiHeader.biYPelsPerMeter = (int) (iYdpi / 2.54f * 100); bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; int iSize = bmi.bmiHeader.biWidth * abs(bmi.bmiHeader.biHeight) * bmi.bmiHeader.biBitCount / 8; uint8_t *pBuf = new uint8_t[iSize]; bRes = !!GetDIBits(hDC, hBmp, 0, abs(bmi.bmiHeader.biHeight), pBuf, &bmi, DIB_RGB_COLORS); for (i = 0; i < iSize; i += 4)// Util::Swap(pBuf[i], pBuf[i + 2]); pBuf[i / 4] = pBuf[i]; m_pTexture = new CTexture(); bRes = m_pTexture->Init(bmi.bmiHeader.biWidth, abs(bmi.bmiHeader.biHeight), DXGI_FORMAT_R8_UNORM, 1, pBuf, bmi.bmiHeader.biWidth /* * bmi.bmiHeader.biBitCount / 8*/, 0);/* ID3D11Resource *pTexRes = 0; m_pTexture->m_pTextureView->GetResource(&pTexRes); D3DX11SaveTextureToFile(CGraphics::Get()->m_pDeviceContext, pTexRes, D3DX11_IFF_BMP, "font.bmp"); SAFE_RELEASE(pTexRes);*/ delete [] pBuf; DeleteObject(hBrush); DeleteObject(hBmp); DeleteObject(hFont); DeleteDC(hDC); if (!InitModel()) return false; return true;}
开发者ID:aaalexandrov,项目名称:Alex,代码行数:101,
示例20: DoPasteVOIDDoPaste( IN PCONSOLE_INFORMATION Console )/*++ Perform paste request into old app by sucking out clipboard contents and writing them to the console's input buffer--*/{ BOOL Success; HANDLE ClipboardDataHandle; if (Console->Flags & CONSOLE_SCROLLING) { return; } // // Get paste data from clipboard // Success = OpenClipboard(Console->hWnd); if (!Success) return; if (Console->CurrentScreenBuffer->Flags & CONSOLE_TEXTMODE_BUFFER) { PWCHAR pwstr; ClipboardDataHandle = GetClipboardData(CF_UNICODETEXT); if (ClipboardDataHandle == NULL) { CloseClipboard(); // Close clipboard return; } pwstr = GlobalLock(ClipboardDataHandle); DoStringPaste(Console,pwstr,GlobalSize(ClipboardDataHandle)); GlobalUnlock(ClipboardDataHandle); } else { HBITMAP hBitmapSource,hBitmapTarget; HDC hDCMemSource,hDCMemTarget; BITMAP bm; PSCREEN_INFORMATION ScreenInfo; hBitmapSource = GetClipboardData(CF_BITMAP); if (hBitmapSource) { ScreenInfo = Console->CurrentScreenBuffer; NtWaitForSingleObject(ScreenInfo->BufferInfo.GraphicsInfo.hMutex, FALSE, NULL); hBitmapTarget = CreateDIBitmap(ScreenInfo->Console->hDC, &ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo->bmiHeader, CBM_INIT, ScreenInfo->BufferInfo.GraphicsInfo.BitMap, ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo, ScreenInfo->BufferInfo.GraphicsInfo.dwUsage ); if (hBitmapTarget) { hDCMemTarget = CreateCompatibleDC ( Console->hDC ); hDCMemSource = CreateCompatibleDC ( Console->hDC ); SelectObject( hDCMemTarget, hBitmapTarget ); SelectObject( hDCMemSource, hBitmapSource ); GetObjectW(hBitmapSource, sizeof (BITMAP), (LPSTR) &bm); BitBlt ( hDCMemTarget, 0, 0, bm.bmWidth, bm.bmHeight, hDCMemSource, 0, 0, SRCCOPY); GetObjectW(hBitmapTarget, sizeof (BITMAP), (LPSTR) &bm); // copy the bits from the DC to memory GetDIBits(hDCMemTarget, hBitmapTarget, 0, bm.bmHeight, ScreenInfo->BufferInfo.GraphicsInfo.BitMap, ScreenInfo->BufferInfo.GraphicsInfo.lpBitMapInfo, ScreenInfo->BufferInfo.GraphicsInfo.dwUsage); DeleteDC(hDCMemSource); DeleteDC(hDCMemTarget); DeleteObject(hBitmapTarget); InvalidateRect(Console->hWnd,NULL,FALSE); // force repaint } NtReleaseMutant(ScreenInfo->BufferInfo.GraphicsInfo.hMutex, NULL); } } CloseClipboard(); return;}
开发者ID:mingpen,项目名称:OpenNT,代码行数:87,
示例21: image_query_bitsvoidimage_query_bits( Handle self, Bool forceNewImage){ PImage i = ( PImage) self; XBITMAPINFO xbi; BITMAPINFO * bi; int newBits; HDC ops = nil; BITMAP bitmap; if ( forceNewImage) { ops = sys ps; if ( !ops) { if ( !( sys ps = dc_alloc())) return; } } if ( !GetObject( sys bm, sizeof( BITMAP), ( LPSTR) &bitmap)) { apiErr; return; // if GetObject fails to get even BITMAP, there will be no good in farther run for sure. } if (( bitmap. bmPlanes == 1) && ( ( bitmap. bmBitsPixel == 1) || ( bitmap. bmBitsPixel == 4) || ( bitmap. bmBitsPixel == 8) || ( bitmap. bmBitsPixel == 24) )) newBits = bitmap. bmBitsPixel; else { newBits = ( bitmap. bmBitsPixel <= 4) ? 4 : (( bitmap. bmBitsPixel <= 8) ? 8 : 24); } if ( forceNewImage) { i-> self-> create_empty( self, bitmap. bmWidth, bitmap. bmHeight, newBits); } else { if (( newBits != ( i-> type & imBPP)) || (( i-> type & ~imBPP) != 0)) i-> self-> create_empty( self, i-> w, i-> h, newBits); } bi = image_get_binfo( self, &xbi); if ( !GetDIBits( sys ps, sys bm, 0, i-> h, i-> data, bi, DIB_RGB_COLORS)) apiErr; if (( i-> type & imBPP) < 24) { int j, nColors = 1 << ( i-> type & imBPP); for ( j = 0; j < nColors; j++) { i-> palette[ j]. r = xbi. bmiColors[ j]. rgbRed; i-> palette[ j]. g = xbi. bmiColors[ j]. rgbGreen; i-> palette[ j]. b = xbi. bmiColors[ j]. rgbBlue; } } if ( forceNewImage) { if ( !ops) { dc_free(); } sys ps = ops; }}
开发者ID:Absolight,项目名称:Prima,代码行数:63,
示例22: GetDataFromBitmap/*******************************************************************************// extracts the dimensional information, pixel array, and color table from an// HBITMAP.// hBitmap can be a handle to a DIB or a DDB. This function assumes that DDBs// will not have a palette. If you create a DDB on a 256-color graphics card,// then the DDB will have a palette and this function will fail.//// returns BMK_OK if successfull, and error state otherwise.********************************************************************************/BMGError GetDataFromBitmap( HBITMAP hBitmap, struct BMGImageStruct *img, int remove_alpha ){ unsigned int DIBScanWidth; DIBSECTION DS; HWND hWnd = GetForegroundWindow(); HDC hDC = NULL; HDC hMemDC = NULL; unsigned char red, green, blue; int FreelpBits = 0; unsigned int numBytes; size_t soDIBSECTION = sizeof(DIBSECTION); size_t soBITMAP = sizeof(BITMAP); unsigned char *p, *q, *lpBits, alpha; jmp_buf err_jmp; int error; BMGError bmgerr; /* error handler */ error = setjmp( err_jmp ); if ( error != 0 ) { if ( hMemDC != NULL ) DeleteDC( hMemDC ); if ( hDC != NULL ) ReleaseDC( hWnd, hDC ); if ( FreelpBits ) free( lpBits ); FreeBMGImage( img ); SetLastBMGError( (BMGError)error ); return (BMGError)error; } SetLastBMGError( BMG_OK ); /* check for valid bitmap*/ if ( !hBitmap ) longjmp( err_jmp, (int)errInvalidBitmapHandle ); /* Extract DIBSECTION info from the HBITMAP. numBytes will equal // soDIBSECTION (84) if hBitmap is a handle to a DIBSECTION (DIB). // numBytes will equal soBITMAP (24) if hBitmap is a handle to a // BITMAP (DDB). */ numBytes = GetObject( hBitmap, sizeof(DIBSECTION), &DS ); if ( numBytes == 0 ) longjmp( err_jmp, (int)errWindowsAPI ); img->opt_for_bmp = 1; if ( numBytes == soDIBSECTION ) { img->width = DS.dsBmih.biWidth; img->height = DS.dsBmih.biHeight; img->bits_per_pixel = (unsigned char)DS.dsBmih.biBitCount; if ( img->bits_per_pixel <= 8 && DS.dsBmih.biClrUsed > 0 ) img->palette_size = (unsigned short)DS.dsBmih.biClrUsed; lpBits = (unsigned char *)DS.dsBm.bmBits; } /* this may be a DDB which must be handled differently */ else if ( numBytes == soBITMAP ) { BITMAP bm; BITMAPINFO bmi; if ( GetObject( hBitmap, sizeof(BITMAP), &bm ) == 0 ) longjmp( err_jmp, (int)errWindowsAPI ); /* DDB with a palette */ if ( bm.bmBitsPixel <= 8 ) longjmp( err_jmp, (int)errInvalidPixelFormat ); img->width = bm.bmWidth; img->height = bm.bmHeight; img->bits_per_pixel = (unsigned char)bm.bmBitsPixel; bmi = InternalCreateBMI( bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, BI_RGB ); lpBits = (unsigned char *)calloc( bm.bmHeight * bm.bmWidthBytes, sizeof(unsigned char) ); if ( lpBits == 0 ) longjmp( err_jmp, (int)errMemoryAllocation ); FreelpBits = 1; hDC = GetDC( hWnd ); if ( GetDIBits(hDC, hBitmap, 0, bm.bmHeight, (void *)lpBits, &bmi, DIB_RGB_COLORS ) == 0 ) longjmp( err_jmp, (int)errWindowsAPI ); ReleaseDC( hWnd, hDC ); hDC = NULL; } else /* I have no idea what this is *///.........这里部分代码省略.........
开发者ID:AreaScout,项目名称:mupen64plus-odroid,代码行数:101,
示例23: GetObjectBOOL CDib::Open(HWND hWnd, const char *pFileName, BOOL bOpenFromFile){ /* UINT fuLoad; if(bOpenFromFile==TRUE) fuLoad = LR_CREATEDIBSECTION|LR_LOADFROMFILE|LR_DEFAULTSIZE; else fuLoad = (bOpenFromFile?LR_CREATEDIBSECTION:0)|LR_LOADFROMFILE|LR_DEFAULTSIZE; */ m_hBitmap=(HBITMAP)::LoadImage( bOpenFromFile? NULL : (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE), pFileName, IMAGE_BITMAP, 0,0, //fuLoad); LR_CREATEDIBSECTION|(bOpenFromFile?LR_LOADFROMFILE:0)|LR_DEFAULTSIZE); if(m_hBitmap==NULL){// SetErrors(CMERR_CANT_OPEN_FILE,pFileName); return FALSE; } BITMAP bm; BITMAPINFOHEADER bi; LPBITMAPINFOHEADER lpbi; // 24bit C++ GetData64函数代码示例 C++ GetDC函数代码示例
|