website logo
Auteur
avatar
zzd10h

Forum » » Création-Développement » » Comment capturer un écran en C ?


Posté : 09-03-2014 23:08 icone du post


Merci Alain, cette méthode a l'air de fonctionner.

Je n'avais pas compris que tu parlais de la fonction ReadPixelArray8(). Je restais scotché sur PDTM_READPIXELARRAY des Datatypes


J'ai bien qq chose dans le buffer mais quand je le sauvegarde en fichier (via LibDevil) j'obtiens soit une image majoritairement noire en JPG ou majoritairement blanche en PNG.

Tu n'aurais pas une idée d'où peut provenir mon pb, stp ???

D'ailleurs dans la fonction ReadPixelArray8() :
-à quoi sert le RastPort temporaire (temprastport dans le code ci-dessous) ?
-on a pas besoin de libérer le rastport initialisé par InitRastPort() ?

voir la vignette dans FastView en haut à gauche

http://zzd10h.amiga-ng.org/FastView/ScreenCapture.jpg

et le package avec source et exécutable

http://zzd10h.amiga-ng.org/FastView/ScreenCapture.lha

Merci

Voici ma fonction


void screenCapture()
{
              ;struct Screen *screen = NULL;
            UBYTE  *buffer = NULL ;
            LONG& nbsp;count_pixel = 0 ;
            int&n bsp;largeur = 1920 ;
            int&n bsp;hauteur = 1080 ;
            int&n bsp;profondeur = 32 ;
              ;           
            buffe r = AllocVecTags( (largeur * hauteur * profo ndeur)/8, AVT_ClearWithValue, 0,TAG_END);
      
              ; screen = LockPubScreen("Workbench");
              ;         
            struc t RastPort monrastport; 
            InitR astPort(&monrastport);
            struc t RastPort temprastport; 
            InitR astPort(&temprastport);        &nbs p;    
            monra stport.BitMap=screen->RastPort.BitMap; /* celle du scree n */ 
            Unloc kPubScreen(NULL, screen);
            
            count _pixel = ReadPixelArray8(&monrastport,0,0,1920,1080,buffer,&t emprastport) ;
            print f("count_pixel = %ld \n",count_pixel);
             
            char& nbsp;fileName[1024];
         //   &nb sp;strcpy(fileName,"RAM:Capture.JPG");
              ;strcpy(fileName,"RAM:Capture.PNG");       & nbsp;     

            ILuin t imageName ;         &n bsp;   
              ;ILenum Format; 
              ;               
            ilIni t();    
            ilGen Images(1, &imageName);    
            ilBin dImage(imageName);

        //    if& nbsp;(profondeur == 8) {Format=IL_LUMINANCE;SaveRawBMP8(I,fileNa me);FreeVec(buffer);return;}     as IL_LUMINANCE& nbsp;is bugged in devIL  
            if&nb sp;(profondeur == 24) Format=IL_RGB; 
            if&nb sp;(profondeur == 32) Format=IL_RGBA; 
            ilTex Image(largeur,hauteur,1,profondeur/8,Format,IL_UNSIGNED_BYTE,buffer); 

            ilEna ble(IL_FILE_OVERWRITE); 
            if(!i lSaveImage(fileName)) 
            {&nbs p;
              ;   printf("ilGetError %d !\n",ilGetError()); 
              ;   FreeVec(buffer);       &n bsp;        
              ;   return; 
            }&nbs p;
            ilDel eteImages(1,&imageName); 
              ;                     
            FreeV ec(buffer);
}



Cet article provient de Le site des utilisateurs francophones actuels et futurs d'AmigaOS 4.x
https://amiga-ng.org/viewtopic.php?topic=1821&forum=14