Click here to Skip to main content
15,899,126 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to create Gaussian random number Pin
Christian Graus23-Oct-05 19:34
protectorChristian Graus23-Oct-05 19:34 
QuestionHow to render samply a antialising string? Pin
simonchen.net23-Oct-05 16:53
simonchen.net23-Oct-05 16:53 
AnswerRe: How to render samply a antialising string? Pin
Christian Graus23-Oct-05 16:56
protectorChristian Graus23-Oct-05 16:56 
GeneralRe: How to render samply a antialising string? Pin
simonchen.net23-Oct-05 17:05
simonchen.net23-Oct-05 17:05 
GeneralRe: How to render samply a antialising string? Pin
Christian Graus23-Oct-05 17:07
protectorChristian Graus23-Oct-05 17:07 
Generalplease change your name Pin
Eytukan23-Oct-05 23:08
Eytukan23-Oct-05 23:08 
AnswerRe: How to render samply a antialising string? Pin
David Crow24-Oct-05 3:38
David Crow24-Oct-05 3:38 
QuestionVC++ Beginer wants to resize a pic (make it smaller) and store it on his hard disc Pin
nne-vitamin23-Oct-05 12:29
nne-vitamin23-Oct-05 12:29 
Hi,

How can I resize a pic (make it smaller) and store it on my hard disc?

I found this code on the web. Now I can load and store every pic, but cannot store it with other size. Who can help me with some codes? Thank you very very much!

//----------------------------------------------------------------------------- 
// Does:   Open a File And Load It Into IPicture (Interface) 
// ~~~~    (.BMP .DIB .EMF .GIF .ICO .JPG .WMF) 
// 
// InPut:  sFilePathName - Path And FileName Target To Save 
// ~~~~~   
// 
// OutPut: TRUE If Succeeded... 
// ~~~~~~ 
//----------------------------------------------------------------------------- 
BOOL CPicture::Load(CString sFilePathName) 
//============================================================================= 
{ 
        BOOL bResult = FALSE; 
        CFile PictureFile; 
        CFileException e; 
        int nSize = 0; 
        
        if(m_IPicture != NULL) FreePictureData(); // Important - Avoid Leaks... 
        
        if(PictureFile.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e)) 
        { 
                nSize = PictureFile.GetLength(); 
                BYTE* pBuffer = new BYTE[nSize]; 
                
                if(PictureFile.Read(pBuffer, nSize) > 0) 
                { 
                        if(LoadPictureData(pBuffer, nSize)) bResult = TRUE; 
                } 
                
                PictureFile.Close(); 
                delete [] pBuffer; 
        } 
        else // Open Failed... 
        { 
                TCHAR szCause[255]; 
                e.GetErrorMessage(szCause, 255, NULL); 
                HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd; 
                MessageBoxEx(hWnd, szCause, ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH); 
                bResult = FALSE; 
        } 
        
        m_Weight = nSize; // Update Picture Size Info... 
        
        if(m_IPicture != NULL) // Do Not Try To Read From Memory That Is Not Exist... 
        {      
                m_IPicture->get_Height(&m_Height); 
                m_IPicture->get_Width(&m_Width); 
                // Calculate Its Size On a "Standard" (96 DPI) Device Context 
                m_Height = MulDiv(m_Height, 96, HIMETRIC_INCH); 
                m_Width  = MulDiv(m_Height,  96, HIMETRIC_INCH); 

        } 
        else // Picture Data Is Not a Known Picture Type 
        { 
                m_Height = 0; 
                m_Width = 0; 
                bResult = FALSE; 
        } 
        
        return(bResult); 
} 

//----------------------------------------------------------------------------- 
// Does:   Saves The Picture That Is Stored In The IPicture Object As a Bitmap 
// ~~~~    (Converts From Any Known Picture Type To a Bitmap / Icon File) 
// 
// InPut:  sFilePathName - Path And FileName Target To Save 
// ~~~~~ 
// 
// OutPut: TRUE If Succeeded... 
// ~~~~~~ 
//----------------------------------------------------------------------------- 
BOOL CPicture::SaveAsBitmap(CString sFilePathName) 
//============================================================================= 
{        
        
        
        
        BOOL bResult = FALSE; 
        ILockBytes *Buffer = 0; 
        IStorage   *pStorage = 0; 
        IStream    *FileStream = 0; 
        BYTE       *BufferBytes; 
        STATSTG     BytesStatistics; 
        DWORD       OutData; 
        long        OutStream; 
        CFile       BitmapFile; CFileException e; 
        double      SkipFloat = 0; 
        DWORD       ByteSkip = 0; 
        _ULARGE_INTEGER RealData; 
        
        CreateILockBytesOnHGlobal(NULL, TRUE, &Buffer); // Create ILockBytes Buffer 
        
        HRESULT hr = ::StgCreateDocfileOnILockBytes(Buffer, 
                STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage); 
        
        hr = pStorage->CreateStream(L"PICTURE", 
                STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, 0, &FileStream); 
        
        m_IPicture->SaveAsFile(FileStream, TRUE, &OutStream); // Copy Data Stream 
        FileStream->Release(); 
        pStorage->Release(); 
        Buffer->Flush(); 
        
        // Get Statistics For Final Size Of Byte Array 
        Buffer->Stat(&BytesStatistics, STATFLAG_NONAME); 
        
        // Cut UnNeeded Data Coming From SaveAsFile() (Leave Only "Pure" Picture Data) 
        SkipFloat = (double(OutStream) / 512); // Must Be In a 512 Blocks... 
        if(SkipFloat > DWORD(SkipFloat)) ByteSkip = (DWORD)SkipFloat + 1; 
        else ByteSkip = (DWORD)SkipFloat; 
        ByteSkip = ByteSkip * 512; // Must Be In a 512 Blocks... 
        
        // Find Difference Between The Two Values 
        ByteSkip = (DWORD)(BytesStatistics.cbSize.QuadPart - ByteSkip); 
        
        // Allocate Only The "Pure" Picture Data 
        RealData.LowPart = 0; 
        RealData.HighPart = 0; 
        RealData.QuadPart = ByteSkip; 
        BufferBytes = (BYTE*)malloc(OutStream); 
        if(BufferBytes == NULL) 
        { 
                Buffer->Release(); 
                HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd; 
                MessageBoxEx(hWnd, "Can not allocate enough memory\t", ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH); 
        } 
        
        Buffer->ReadAt(RealData, BufferBytes, OutStream, &OutData); 
        
        if(BitmapFile.Open(sFilePathName, CFile::typeBinary | CFile::modeCreate | CFile::modeWrite, &e)) 
        { 
                BitmapFile.Write(BufferBytes, OutData); 
                BitmapFile.Close(); 
                bResult = TRUE; 
        } 
        else // Write File Failed... 
        { 
                TCHAR szCause[255]; 
                e.GetErrorMessage(szCause, 255, NULL); 
                HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd; 
                MessageBoxEx(hWnd, szCause, ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH); 
                bResult = FALSE; 
        } 
        
        Buffer->Release(); 
        free(BufferBytes); 
        
        return(bResult); 
} 

AnswerRe: VC++ Beginer wants to resize a pic (make it smaller) and store it on his hard disc Pin
Christian Graus23-Oct-05 12:46
protectorChristian Graus23-Oct-05 12:46 
GeneralRe: VC++ Beginer wants to resize a pic (make it smaller) and store it on his hard disc Pin
nne-vitamin23-Oct-05 13:37
nne-vitamin23-Oct-05 13:37 
GeneralRe: VC++ Beginer wants to resize a pic (make it smaller) and store it on his hard disc Pin
Christian Graus23-Oct-05 13:40
protectorChristian Graus23-Oct-05 13:40 
GeneralRe: VC++ Beginer wants to resize a pic (make it smaller) and store it on his hard disc Pin
nne-vitamin23-Oct-05 14:34
nne-vitamin23-Oct-05 14:34 
GeneralRe: VC++ Beginer wants to resize a pic (make it smaller) and store it on his hard disc Pin
normanS23-Oct-05 19:30
normanS23-Oct-05 19:30 
GeneralRe: VC++ Beginer wants to resize a pic (make it smaller) and store it on his hard disc Pin
Christian Graus23-Oct-05 19:31
protectorChristian Graus23-Oct-05 19:31 
GeneralRe: VC++ Beginer wants to resize a pic (make it smaller) and store it on his hard disc Pin
normanS23-Oct-05 21:50
normanS23-Oct-05 21:50 
Questiontime critical thread Pin
LeeeNN23-Oct-05 11:56
LeeeNN23-Oct-05 11:56 
AnswerRe: time critical thread Pin
khan++23-Oct-05 18:18
khan++23-Oct-05 18:18 
AnswerRe: time critical thread Pin
Bob Stanneveld24-Oct-05 0:03
Bob Stanneveld24-Oct-05 0:03 
Questionretrieve DC of window that is hidden behind other windows Pin
Member 231353823-Oct-05 11:14
Member 231353823-Oct-05 11:14 
AnswerRe: retrieve DC of window that is hidden behind other windows Pin
Chris Losinger23-Oct-05 11:40
professionalChris Losinger23-Oct-05 11:40 
AnswerRe: retrieve DC of window that is hidden behind other windows Pin
PJ Arends23-Oct-05 13:49
professionalPJ Arends23-Oct-05 13:49 
QuestionHandling shell command line Pin
Member 230136023-Oct-05 10:56
Member 230136023-Oct-05 10:56 
AnswerRe: Handling shell command line Pin
David Crow24-Oct-05 3:43
David Crow24-Oct-05 3:43 
GeneralRe: Handling shell command line Pin
Allad24-Oct-05 6:51
Allad24-Oct-05 6:51 
GeneralRe: Handling shell command line Pin
David Crow24-Oct-05 7:07
David Crow24-Oct-05 7:07 

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.