Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

error C2664: '(...) Gdiplus::Image::Save (...)': cannot convert parameter 1 from 'IStream *' to 'const WCHAR *'

Ostatnio zmodyfikowano 2012-10-03 19:28
Autor Wiadomość
Admixior
Temat założony przez niniejszego użytkownika
error C2664: '(...) Gdiplus::Image::Save (...)': cannot convert parameter 1 from 'IStream *' to 'const WCHAR *'
» 2012-10-02 22:57:07
Chodzi o GDI+
Mam wskaźnik do klasy Gdiplus::Bitmap
Bitmap* image;

Klasa ta dziedziczy publicznie klasę Gdiplus::Image(która dziedziczy inne itd.);
Klasa Image ma zdeklarowane(i zdefiniowane) 2 funkcje:
Status http://msdn.microsoft.com/en-us/library/windows/desktop/ms535407(v=vs.85).aspx(
  [in]  const WCHAR *filename,
  [in]  const CLSID *clsidEncoder,
  [in]  const EncoderParameters *encoderParams
);

Status http://msdn.microsoft.com/en-us/library/windows/desktop/ms535406(v=vs.85).aspx(
  [in]  IStream *stream,
  [in]  const CLSID *clsidEncoder,
  [in]  const EncoderParameters *encoderParams
);

//Co ciekawe zazwyczaj jak są przeładowania to na jednej stronie, ale co dokumentacja to obyczaj

Wywołuje w ten sposób:
C/C++
IStream * bmptojpg = NULL;
Bitmap * image;
//prace
image->Save( bmptojpg, encoderClsid, encoderParameters );

Problem jest następujący:

error C2664: 'Gdiplus::Status Gdiplus::Image::Save(const WCHAR *,const CLSID *,const Gdiplus::EncoderParameters *)' : cannot convert parameter 1 from 'IStream *' to 'const WCHAR *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

//czemu te linki tak dziwnie  działają?
P-65988
DejaVu
» 2012-10-03 01:24:08
C/C++
// ScreenCapture.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <gdiplus.h>

using namespace Gdiplus;

int GetEncoderClsid( const WCHAR * format, CLSID * pClsid )
{
    UINT num = 0; // number of image encoders
    UINT size = 0; // size of the image encoder array in bytes
   
    ImageCodecInfo * pImageCodecInfo = NULL;
   
    GetImageEncodersSize( & num, & size );
    if( size == 0 )
         return - 1; // Failure
   
    pImageCodecInfo =( ImageCodecInfo * )( malloc( size ) );
    if( pImageCodecInfo == NULL )
         return - 1; // Failure
   
    GetImageEncoders( num, size, pImageCodecInfo );
   
    for( UINT j = 0; j < num; ++j )
    {
        if( wcscmp( pImageCodecInfo[ j ].MimeType, format ) == 0 )
        {
            * pClsid = pImageCodecInfo[ j ].Clsid;
            free( pImageCodecInfo );
            return j; // Success
        }
    }
   
    free( pImageCodecInfo );
    return - 1; // Failure
}

void ScreenShot( void )
{
    HGLOBAL hMem;
    HDC hdcScreen = CreateDC( _T( "DISPLAY" ), NULL, NULL, NULL );
    HDC hdcCapture = CreateCompatibleDC( hdcScreen );
    int nWidth = GetDeviceCaps( hdcScreen, HORZRES ),
    nHeight = GetDeviceCaps( hdcScreen, VERTRES ),
    nBPP = GetDeviceCaps( hdcScreen, BITSPIXEL );
   
    LPBYTE lpCapture;
    BITMAPINFO bmiCapture = { {
            sizeof( BITMAPINFOHEADER ), nWidth, - nHeight, 1, nBPP, BI_RGB, 0, 0, 0, 0, 0,
        } };
   
    HBITMAP hbmCapture = CreateDIBSection( hdcScreen, & bmiCapture,
    DIB_PAL_COLORS,( LPVOID * ) & lpCapture, NULL, 0 );
   
    if( !hbmCapture ) {
        DeleteDC( hdcCapture );
        DeleteDC( hdcScreen );
        return;
    }
   
    int nCapture = SaveDC( hdcCapture );
    SelectObject( hdcCapture, hbmCapture );
    BitBlt( hdcCapture, 0, 0, nWidth, nHeight, hdcScreen, 0, 0, SRCCOPY );
    RestoreDC( hdcCapture, nCapture );
    DeleteDC( hdcCapture );
    DeleteDC( hdcScreen );
   
    if( hMem = GlobalAlloc( GMEM_MOVEABLE, 0 ) )
    {
        IStream * pStream;
       
        if( CreateStreamOnHGlobal( hMem, FALSE, & pStream ) == S_OK )
        {
            // save the buffer to a file
            Bitmap * pScreenShot = new Bitmap( hbmCapture,( HPALETTE ) NULL );
            CLSID imageCLSID;
            Status result;
           
            GetEncoderClsid( L"image/jpeg", & imageCLSID );
           
            result = pScreenShot->Save( pStream, & imageCLSID );
           
            pStream->Release();
           
            if( result == Ok )
            {
                unsigned char * pBytes;
               
                if( pBytes =( unsigned char * ) GlobalLock( hMem ) )
                {
                    /*
                    * pBytes now points to your image file in memory
                    *  in whatever format was specified by your encoder
                    *        parameter.
                    */
                    DWORD size = GlobalSize( hMem );
                    FILE * fp;
                   
                    if( fp = _tfopen( _T( "c:\\test.jpg" ), _T( "wb" ) ) )
                    {
                        fwrite( pBytes, size, 1, fp );
                        fclose( fp );
                    }
                }
            }
           
        }
        else
        {
            printf( "error CreateStreamOnHGlobal. Last err: %d\n", GetLastError() );
            return;
        }
    }
    else
    {
        printf( "error GlobalAlloc. Last err: %d\n", GetLastError() );
        return;
    }
}


int _tmain( int argc, _TCHAR * argv[] )
{
    ULONG_PTR gdiplusToken;
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup( & gdiplusToken, & gdiplusStartupInput, NULL );
   
    ScreenShot();
   
    return 0;
}
Źródło: http://www.experts-exchange.com/Programming/System /Windows__Programming/Q_24381537.html#

Może Ciebie to na coś naprowadzi... w każdym razie spróbuj zrobić "Go to declaration" i zobaczyć czy istnieje deklaracja wymienionej przez Ciebie metody.

/edit:
http://www.microsoftfaqs.com/msg/1472680.aspx
http://www.44342.com/win32-f36-t4095-p1.htm

/edit2:
Z tego co się doczytałem to chodzi o to, że do drugiego (trzeciego) argumentu metody podajesz obiekt zamiast wskaźnik na obiekt.
P-65989
Admixior
Temat założony przez niniejszego użytkownika
» 2012-10-03 19:28:03
Tak drugi i trzeci parametr był nie poprawny bo powinno być &
if (image->Image::Save(bmptojpg,&encoderClsid,&encoderParameters) == S_OK)

THX
P-66003
« 1 »
  Strona 1 z 1