Common image processing functions of Deng Zhenbo
In Visual C , the functions that can be provided for image operations are relatively weak. I collected some methods and techniques that have been mastered in practice, summarize a CoperateBitMap class, which can achieve convenient image The read, save, clipboard operation, DIB and DDB conversion, the header file is listed below, and I write it into an MFC extension DLL. Click here to download. 1. Convenient to load various graphic formats (JPG, BMP, GIF, etc.) files from disk, and get the image size and the handle of the corresponding bitmap, so that various image formats can be easily operated without understanding the format of various images. , As well as the corresponding compression decompression algorithm, the obtained bitmap handle, can be convenient to various operations in the VC. 2. Put the bit drawing to the DC, which is convenient to draw the bitmap to the device DC, no complex SelectObject, etc. 3, create a variety of shapes of window 4, convenient two bitmap replication operations, Support partial area copy 5, no streetchblt function, directly change the size of the bitmap, stretchblt only changes the displayed size, the actual data does not change, the scalebitmap in this class can directly change the actual size of the actual data, this will be useful Function 6, DDB and DIB conversion 7, save bitmaps to files, saved as JPEG files
This class does not make too much optimization and function expansion, and this class may not apply if you want to write a professional image operation program.
class COperateBitmap {public: BOOL CopyWindowToClipboard (CWnd * pWnd); // clipboard operations BOOL CopyDIBToClipboard (const CWnd * pWnd, HANDLE hDib, CPalette * pPal); BOOL CopyBitmapToClipboard (const CWnd * pWnd, CBitmap & bitmap, CPalette * pPal); // create toner Edition, according DIBBOOL CreateDIBPalette (HANDLE hDIB, CPalette * pPal); // DDB and DIB conversion HANDLE DDBToDIB (HBITMAP hBmp, DWORD dwCompression, CPalette * pPal); HBITMAP DIBToDDB (HANDLE hDIB); HANDLE DDBToDIB ( CBITMAP & Bitmap, DWORD DWCompRESSION, CPALETTE * PPAL); INT SaveBMP (Handle HDIB, LPSTR FileName); // Load a variety of graphics formats (JPG, BMP, GIF, etc.) from the file, and get the handle of the size and bitmap Void LoadPictureFromFile ( HDC HDC, LPCTSTR SZFILE, CBITMAP * PBITMAP, CSIZE & MSIZE); // Put the bit drawing to Void Drawbitmap (CDC * DC, HBitmap HBMP, Rect R, Bool Stretch); // Established Zone BOOL CREATEREGION (Rect R, CRGN * prgn, cbitmap * pbitmap, colorref keycol); // Two bitmaps VOID CopyBitmap (CDC * DC, CBITMAP & MRES, CONST CBITMAP & HBMP, RECT R); // is mapped to the area HRGN Bitmaptoregion (Hbitmap HBMP, ColorRef CTransparentColor = 0, colorref ctolerance = 0x101010); CoperateBitMap (); // Zoom image main function, by ivaylo by alko write HBITMAP ScaleBitmap (HBITMAP hBmp, WORD wNewWidth, WORD wNewHeight); // save DIB as a JPEG file BOOL JpegFromDib (HANDLE hDib, // Handle to DIBint nQuality, // JPEG quality (0-100) CString strJpegFileName, // Pathname to target jpeg fileCString * strMsg); // Error msg to returnvirtual ~ COperateBitmap (); protected: // the following three scaled image helper function, written by Ivaylo Byalko BITMAPINFO * PrepareRGBBitmapInfo (WORD wWidth, WORD wHeight); void ShrinkData ( BYTE * pInBuff, WORD wWidth, WORD wHeight, BYTE * pOutBuff, WORD wNewWidth, WORD wNewHeight); void EnlargeData (BYTE * pInBuff, WORD wWidth, WORD wHeight, BYTE * pOutBuff, WORD wNewWidth, WORD wNewHeight); WORD DIBNumColors (LPSTR lpbi Word Palettesize (LPSTR LPBI);
float * CreateCoeff (int nLen, int nNewLen, BOOL bShrink); // operation JPEG file BOOL BuildSamps (HANDLE hDib, int nSampsPerRow, struct jpeg_compress_struct cinfo, JSAMPARRAY jsmpArray, CString * pcsMsg); RGBQUAD QuadFromWord (WORD b16); BOOL DibToSamps ( Handle HDIB, INT NSAMPSPERROW, STRUCT JPEG_COMPRESS_STRUCT CINFO, JSAMPARRAY JSMPPIXELS, CSTRING * PCSMSG);}; Download Project Source File
For more articles, please visit http://seesi.51.net