website logo
Auteur
avatar
thellier

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


Posté : 07-03-2014 10:33 icone du post

>comment faire pour sauver le bitmap en fichier autre que ILBM ?

Prends libjpeg ou DevIL:
Tu créé un buffer ram de la taille bitmap (cad taille=large*haut*3)
tu copie ta bitmap dans le buffer avec readpixel array
tu sauve le buffer en tant qu'image jpg


Voici 2 bouts de code pour DevIL et LibJPG

/*==========================================================================* /
void SaveDEVIL(struct image3D *I,UBYTE *filename)
{
/* Save Texture to any kind of Image file with DevIL.dll */

ILuint ImageName;
ILenum Format;
ILAPI ILvoid ILAPIENTRY ilRegisterPal(ILvoid *Pal, ILuint Size, ILenum Type);


if(!DevilLibraryON) InitDEVIL();
if(!DevilLibraryON) return;

if(I ==NULL) return;
if(I->pt==NULL) return;
if(DevilDebugON) printf("SaveTextureDEVIL %dX%d %d bits to <%s>\n",I->large,I->high,I->bits,filename);
if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION )
{
if(DevilDebugON) printf("Your IL version < %d !\n",IL_VERSION);
return;
}

ilGenImages(1, &ImageName);
ilBindImage(ImageName);

/* IL_COLOR_INDEX IL_LUMINANCE IL_LUMINANCE_ALPHA */

if(I->bits==8) {Format=IL_LUMINANCE;SaveRawBMP8(I,filename);return;} /* as IL_LUMINANCE is bugged in devIL */
if(I->bits==24) Format=IL_RGB;
if(I->bits==32) Format=IL_RGBA;
ilTexImage(I->large,I->high,1,I->bits/8,Format,IL_UNSIGNED_BYTE,I->pt);

ilEnable(IL_FILE_OVERWRITE);
if(!ilSaveImage(filename))
{
if(DevilDebugON) printf("ilGetError %d !\n",ilGetError());
return;
}
ilDeleteImages(1,&ImageName);

return;
}

/*==========================================================================* /
unsigned int SaveJPG(struct image3D *I,char * filename,int quality)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPROW imagescanline[1]; /* pointer to JSAMPLE row[s] */
int bytesperline; /* physical row width in image buffer */
int n;
FILE * fp;

if(JpegDebugON) printf("JPEG File <%s> \n", filename);
if ((fp = fopen(filename, "wb")) == 0)
{
if(JpegDebugON) printf("can't open %s\n", filename);
return(FALSE);
}

cinfo.err = jpeg_std_error(&jerr);

if(JpegDebugON) printf("Writing JPEG %d X %d X %d Bits from Memory(%ld)\n",I->large,I->high,I->bits,I->pt);
if (I->pt==NULL)
{if(JpegDebugON) printf("Given Image pt==NULL !\n");return(FALSE);}

jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, fp);

cinfo.image_width = I->large; /* image width and height, in pixels */
cinfo.image_height = I->high;
cinfo.input_components = I->bits/8; /* # of color components per pixel */
if (I->bits==24)
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
else
cinfo.in_color_space = JCS_GRAYSCALE; /* colorspace of input image */


jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
jpeg_start_compress(&cinfo, TRUE);

bytesperline = I->large*(I->bits/8);

NLOOP(I->high)
{
imagescanline[0] = & (I->pt[n*bytesperline]);
(void) jpeg_write_scanlines(&cinfo, imagescanline, 1);
}

jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
fclose(fp);
return(TRUE);
}


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