Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    455

    [C++]inserire immagine

    vorrei inserire un immagine in alto al mio programma,potete postarmi qui il codice se possibile? (uso come compilatore dev-c++)

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Beh ... sei piuttosto sbrigativo nelle richieste ...

    Magari sarebbe meglio dirci di che tipo di programma stiamo parlando e di quale tipo di file immagine ...

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    455
    veramente il programma sarebbe un test,per capire come mettere un immagine e il formato immagine sarebbe jpg oppure bmp

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Quando ti chiedevo il "tipo di programma" volevo sapere quale compilatore utilizzi e cosa hai fatto per creare il programma ... hai creato una finestra, hai una dialog box, hai usato un contenitore di tipo image ... insomma descrivi un po' quello che hai fatto ...

    Puoi usare piu' di 2 righe quando scrivi nel forum ...

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    455
    allora il compilatore è BloodShed dev-c++
    ho creato una windows application e poi non ho fatto nient'altro

  6. #6
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Allora ... dove c'e' lo switch(message) inserisci

    codice:
            case WM_PAINT:
                {
                     PAINTSTRUCT   ps;
                     HBITMAP       hBitmap, hOldBitmap;
                     HPALETTE      hPalette, hOldPalette;
                     HDC           hDC, hMemDC;
                     BITMAP        bm;
                    
                    hDC = BeginPaint(hwnd, &ps);
                    
                    if(LoadBitmapFromBMPFile("C:\\TuaCartella\\TuoFile.bmp", &hBitmap, &hPalette))
                    {
                      GetObject( hBitmap, sizeof(BITMAP), &bm );
                      hMemDC = CreateCompatibleDC( hDC );
                      hOldBitmap = (HBITMAP)SelectObject( hMemDC, hBitmap );
                      hOldPalette = SelectPalette( hDC, hPalette, FALSE );
                      RealizePalette( hDC );
                    
                      BitBlt(hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
                    
                      SelectObject(hMemDC, hOldBitmap);
                      DeleteObject(hBitmap);
                      SelectPalette hDC, hOldPalette, FALSE );
                      DeleteObject(hPalette);
                    }
        
                    EndPaint(hwnd, &ps);
                }
                break;
    mettendo il path completo del nome del file bmp (deve essere bmp ...).

    E inserisci la funzione

    codice:
    BOOL LoadBitmapFromBMPFile( LPTSTR szFileName, HBITMAP *phBitmap, HPALETTE *phPalette )
    {
       BITMAP  bm;
    
       *phBitmap = NULL;
       *phPalette = NULL;
    
       // Use LoadImage() to get the image loaded into a DIBSection
       *phBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
                   LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
       if( *phBitmap == NULL )
         return FALSE;
    
       // Get the color depth of the DIBSection
       GetObject(*phBitmap, sizeof(BITMAP), &bm );
       // If the DIBSection is 256 color or less, it has a color table
       if( ( bm.bmBitsPixel * bm.bmPlanes ) <= 8 )
       {
       HDC           hMemDC;
       HBITMAP       hOldBitmap;
       RGBQUAD       rgb[256];
       LPLOGPALETTE  pLogPal;
       WORD          i;
    
       // Create a memory DC and select the DIBSection into it
       hMemDC = CreateCompatibleDC( NULL );
       hOldBitmap = (HBITMAP)SelectObject( hMemDC, *phBitmap );
       // Get the DIBSection's color table
       GetDIBColorTable( hMemDC, 0, 256, rgb );
       // Create a palette from the color tabl
       pLogPal = (LOGPALETTE *)malloc( sizeof(LOGPALETTE) + (256*sizeof(PALETTEENTRY)) );
       pLogPal->palVersion = 0x300;
       pLogPal->palNumEntries = 256;
       for(i=0;i<256;i++)
       {
         pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed;
         pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen;
         pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue;
         pLogPal->palPalEntry[i].peFlags = 0;
       }
       *phPalette = CreatePalette( pLogPal );
       // Clean up
       free( pLogPal );
       SelectObject( hMemDC, hOldBitmap );
       DeleteDC( hMemDC );
       }
       else   // It has no color table, so use a halftone palette
       {
       HDC    hRefDC;
    
       hRefDC = GetDC( NULL );
       *phPalette = CreateHalftonePalette( hRefDC );
       ReleaseDC( NULL, hRefDC );
       }
       return TRUE;
    }

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    455
    il primo codice non so dove metterlo...lo swith(message) non lo trovo

  8. #8
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Ce l'hai una funzione

    WindowProcedure


    ?

  9. #9
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    455
    purtroppo no

  10. #10
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Hai detto di aver creato una

    windows application

    e quindi ci deve essere quella funzione ...

    Quale versione usi di DevC++?

    Quale codice ha generato?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.