- BOOL BmpToJpg( int nWidth, int nHeight, int nPixelBytes, BYTE* byBmpData, BYTE** byJpgData, unsigned long* nSize )
- {
- BOOL bResult = FALSE;
- jpeg_compress_struct jCompress;
- jpeg_error_mgr jErrorMgr;
- jCompress.err = jpeg_std_error( &jErrorMgr );
- jpeg_create_compress( &jCompress );
- jpeg_mem_dest( &jCompress, byJpgData, nSize );
- jCompress.image_width = nWidth;
- jCompress.image_height = nHeight;
- jCompress.input_components = nPixelBytes;
- jCompress.in_color_space = JCS_UNKNOWN;
- jpeg_set_defaults( &jCompress );
- jpeg_set_quality ( &jCompress, 70, true );
- jpeg_start_compress( &jCompress, true );
- int nLineWidth = nWidth * nPixelBytes;
- for ( int i = 0; i < nHeight; ++i )
- {
- BYTE* lpJpgBits = byBmpData + ( nHeight - i - 1 ) * nLineWidth;
- JSAMPROW row_pointer = lpJpgBits;
- jpeg_write_scanlines( &jCompress, &row_pointer, 1 );
- }
- jpeg_finish_compress( &jCompress );
- jpeg_destroy_compress( &jCompress );
- return bResult;
- }
- BOOL JpgToBmp( BYTE* byJpgData, BYTE* byBmpData, unsigned long* nSize )
- {
- BOOL bResult = FALSE;
- jpeg_decompress_struct jDecompress;
- jpeg_error_mgr jErrorMgr;
- jDecompress.err = jpeg_std_error( &jErrorMgr );
- jpeg_create_decompress( &jDecompress );
- jpeg_mem_src( &jDecompress, byJpgData, *nSize );
- jpeg_read_header( &jDecompress, true );
- jpeg_start_decompress( &jDecompress );
- int nHeight = jDecompress.output_height;
- int nLineWidth = jDecompress.output_components * jDecompress.output_width;
- for ( int i = 0; i < nHeight; ++i )
- {
- BYTE* lpBmBits = byBmpData + ( nHeight - i - 1 ) * nLineWidth;
- jpeg_read_scanlines( &jDecompress, &lpBmBits, 1 );
- }
- jpeg_finish_decompress( &jDecompress );
- jpeg_destroy_decompress( &jDecompress );
- *nSize = nLineWidth * nHeight;
- return bResult;
- }
jpeglib的使用
最新推荐文章于 2024-05-24 08:55:25 发布