Click here to Skip to main content
16,012,061 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionChange Caption Bar Color Pin
Sukant Tiwary13-Mar-06 23:32
Sukant Tiwary13-Mar-06 23:32 
AnswerRe: Change Caption Bar Color Pin
Hamid_RT14-Mar-06 1:02
Hamid_RT14-Mar-06 1:02 
QuestionHelp! strange problem with CRecordset Pin
chev_ls113-Mar-06 23:21
chev_ls113-Mar-06 23:21 
AnswerRe: Help! strange problem with CRecordset Pin
David Crow14-Mar-06 3:08
David Crow14-Mar-06 3:08 
QuestionMouse Hook; works only within dialog window Pin
pc_dev13-Mar-06 23:13
pc_dev13-Mar-06 23:13 
AnswerRe: Mouse Hook; works only within dialog window Pin
Naveen13-Mar-06 23:35
Naveen13-Mar-06 23:35 
QuestionQuestion about waveInGetPosition Pin
Remco Hoogenboezem13-Mar-06 23:10
Remco Hoogenboezem13-Mar-06 23:10 
QuestionHow to reduce the size of an Image using GDI+ Pin
snprani@yahoo.com13-Mar-06 22:59
snprani@yahoo.com13-Mar-06 22:59 
Hai to all,

Can anybody understand this function can you please explain me. by using this function the size of the image we are storing is increasing the size. I have to reduce that size. I am unable to find what to do. with out using this function the size of the image is 40kb and after using this function it size become 622kb. I am using Black and while image. I think by reading any image by Gdiplus Image function it will take it into color mode. becoz of that it is taking large size.

If possible can tell me how to reduce the size of the image.


CLogEntry CDocImage::MergeSignRegions(LPCTSTR szSaveFileName, FocusSide nSide ) {

CLogEntry retcode;
CString csError ;
Bitmap *pbmBase = NULL ;
Gdiplus::Image *pImageIn = NULL ;
Status saveStatus ;

// Don't do anything if there is no sign regions for this side.
if ((nSide == Side1 && m_ptaSignRegions.GetSize() == 0) ||
(nSide == Side2 && m_ptaSignRegions2.GetSize() == 0))
return retcode;

TCHAR szTempPath[MAX_PATH] = "\0";
TCHAR szSigTempFile[MAX_PATH] = "\0";
TCHAR szBaseTempFile[MAX_PATH] = "\0";

if ( !::GetTempPath( MAX_PATH, szTempPath ) ) {
VXTRACE();
return CLogEntry("Failed to get temp path.", -1);
}

// Get the number of sign regions of this side
int nSignRegionCount = 0;
if (nSide == Side1)
nSignRegionCount = m_ptaSignRegions.GetSize();
else
nSignRegionCount = m_ptaSignRegions2.GetSize();

// Load the saved document image and merge all signatures
try {
CLSID encoderClsid ;
WCHAR wcFileName[_MAX_PATH*sizeof(WCHAR)] ;
WCHAR wcTempName[_MAX_PATH*sizeof(WCHAR)] ;
WCHAR wcSaveName[_MAX_PATH*sizeof(WCHAR)] ;
LPCTSTR pszFileName ;
CDC memDC, sigDC ; // memory DC into which main image will be loaded
HBITMAP hbm, hbmSig ;

memDC.CreateCompatibleDC( CDC::FromHandle( ::GetDC( NULL ) ) ) ; // .like display.
sigDC.CreateCompatibleDC( CDC::FromHandle( ::GetDC( NULL ) ) ) ; // .like display.

if ( nSide == Side1 )
pszFileName = m_szFilename ;
else
pszFileName = m_szFilename2 ;

//--- Read in document image, as a tif
mbstowcs( wcFileName, pszFileName, sizeof( wcFileName ) ) ;
pImageIn = new Gdiplus::Image( wcFileName, false ) ;

if (!::GetTempFileName(szTempPath, "BAS", 0, szBaseTempFile)) {
VXTRACE() ;
return CLogEntry( _T("Failed to get base temp path"), -1 ) ;
}

// Get the CLSID of the BMP encoder
if ( GetEncoderClsid( L"image/tiff" /*L"image/bmp"*/, &encoderClsid ) == -1 ) {
::DeleteFile( szBaseTempFile ) ;
VXTRACE() ;
return CLogEntry( _T("Cannot find encoder clsid for BMP encoder"), -1 ) ;
}

//--- Save the document image as a bmp
mbstowcs( wcFileName, szBaseTempFile, sizeof( wcFileName ) ) ;
pImageIn->Save( wcFileName, &encoderClsid, NULL ) ;


//--- Reload document as a GDI+ BMP Image
pbmBase = new Bitmap( wcFileName, false ) ;

PixelFormat pxfBase = pbmBase->GetPixelFormat() ;

//--- Put base document bitmap into memory dc
Status status = pbmBase->GetHBITMAP( NULL, &hbm ) ;
memDC.SelectObject( hbm ) ;

CDC adc ; // memory DC for result
CBitmap bmp ; // will contain the composite image

bmp.CreateCompatibleBitmap( &memDC, pbmBase->GetWidth(), pbmBase->GetHeight() ) ;
adc.CreateCompatibleDC( &memDC ) ;
adc.SelectObject( bmp.m_hObject ) ;

//--- Suck the composite image out of the assembly dc, into a bmp that we can use
adc.BitBlt( 0, 0, pbmBase->GetWidth(), pbmBase->GetHeight(), &memDC, 0, 0, SRCCOPY ) ;

CPalette *pPal = memDC.GetCurrentPalette() ;
Bitmap *pSigMap = new Bitmap( (HBITMAP)bmp.m_hObject, (HPALETTE) pPal->m_hObject ) ;

if ( GetEncoderClsid( L"image/tiff", &encoderClsid ) == -1 ) {
VXTRACE() ;
return CLogEntry( _T("Cannot find encoder clsid for tiff encoder"), -1 ) ;
}

//--- Create a 2-parameter array, for Compression and for Color Bit depth
EncoderParameters* pEncoderParameters = (EncoderParameters*) malloc(sizeof(EncoderParameters)
+ 1 * sizeof(EncoderParameter));

//--- Use LZW Compression instead of Group 4, since it works for color and G4 doesn't
ULONG ulCompression = EncoderValueCompressionLZW ;

//--- 24-bit seems to be the SMALLEST one that works here - it might be the image, since
//--- the encoder claims to work for smaller values, but disk space is cheep.
ULONG ulColorDepth = 24L ;

pEncoderParameters->Count = 2 ;
pEncoderParameters->Parameter[0].NumberOfValues = 1 ;
pEncoderParameters->Parameter[0].Guid = EncoderCompression ;
pEncoderParameters->Parameter[0].Type = EncoderParameterValueTypeLong ;
pEncoderParameters->Parameter[0].Value = &ulCompression ;
pEncoderParameters->Parameter[1].NumberOfValues = 1 ;
pEncoderParameters->Parameter[1].Guid = EncoderColorDepth ;
pEncoderParameters->Parameter[1].Type = EncoderParameterValueTypeLong ;
pEncoderParameters->Parameter[1].Value = &ulColorDepth ;

mbstowcs( wcSaveName, szSaveFileName, sizeof( wcSaveName ) ) ;
saveStatus = pSigMap->Save( wcSaveName, &encoderClsid, pEncoderParameters ) ;

if ( saveStatus != Ok ) {
VXTRACE() ;
csError.Format( _T("Bitmap::Save failed for %s, error %d"), szSaveFileName, saveStatus ) ;
return CLogEntry( csError, -1 ) ;
}

} catch ( Exception error ) {
csError.Format( _T("ImageMagick Exception: %s"), error.what() ) ;
retcode = CLogEntry( csError, -1 ) ;
}

//--- can't delete the temporary file used for the Bitmap object while that object still exists
if ( pbmBase )
delete pbmBase ;

if ( pImageIn )
delete pImageIn ;

if ( *szBaseTempFile ) {
if ( !::DeleteFile( szBaseTempFile ) ) {
csError.Format( _T("DeleteFile failed for %s, error %d"), szSigTempFile, ::GetLastError() ) ;
return CLogEntry( csError, -1 ) ;
}
}

VETRACE();

return retcode ;
}
QuestionAccessing DHCP Lease Table Pin
activee13-Mar-06 22:53
activee13-Mar-06 22:53 
QuestionBypass proxy Pin
Girish60113-Mar-06 22:51
Girish60113-Mar-06 22:51 
Questiondestroying and loading Forms:VC++ .NET Pin
luhfluh13-Mar-06 22:45
luhfluh13-Mar-06 22:45 
QuestionBackspace problem in ActiveX embeded in IE Pin
Muhammad Azam13-Mar-06 22:34
Muhammad Azam13-Mar-06 22:34 
AnswerRe: Backspace problem in ActiveX embeded in IE Pin
khan++14-Mar-06 1:54
khan++14-Mar-06 1:54 
GeneralRe: Backspace problem in ActiveX embeded in IE Pin
Muhammad Azam14-Mar-06 6:37
Muhammad Azam14-Mar-06 6:37 
GeneralRe: Backspace problem in ActiveX embeded in IE Pin
khan++14-Mar-06 19:21
khan++14-Mar-06 19:21 
QuestionFiles Pin
chaitanya2213-Mar-06 22:33
chaitanya2213-Mar-06 22:33 
AnswerRe: Files Pin
Ray Kinsella13-Mar-06 22:36
Ray Kinsella13-Mar-06 22:36 
AnswerRe: Files Pin
kakan13-Mar-06 22:37
professionalkakan13-Mar-06 22:37 
GeneralRe: Files Pin
chaitanya2213-Mar-06 23:19
chaitanya2213-Mar-06 23:19 
GeneralRe: Files Pin
kakan13-Mar-06 23:42
professionalkakan13-Mar-06 23:42 
GeneralRe: Files Pin
chaitanya2214-Mar-06 5:20
chaitanya2214-Mar-06 5:20 
GeneralRe: Files Pin
kakan14-Mar-06 19:20
professionalkakan14-Mar-06 19:20 
QuestionHELP!!!... ODBC CRecordSet based MFC application slowing down to unusable speeds!! :( Pin
chev_ls113-Mar-06 22:28
chev_ls113-Mar-06 22:28 
AnswerRe: HELP!!!... ODBC CRecordSet based MFC application slowing down to unusable speeds!! :( Pin
Stephen Hewitt13-Mar-06 22:31
Stephen Hewitt13-Mar-06 22:31 
GeneralRe: HELP!!!... ODBC CRecordSet based MFC application slowing down to unusable speeds!! :( Pin
chev_ls113-Mar-06 22:41
chev_ls113-Mar-06 22:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.