Save image code from Desktop

Hi,
I downloaded sample implementation from here: http://www.khronos.org/registry/vg/ri/openvg-1.1-ri.zip

Everything works well and I can get the rendered image. Now I want to save the rendered image onto my PC as .bmp. Does anyone have a code for that? I need to do this after calling vgReadPixels(

Thanks!

Your best bet is to download a library to do that for you.
I recommend the FreeImage library from http://freeimage.sourceforge.net/
or something similar.

The alternative is to write it yourself. The BMP format is fairly simple and supports uncompressed formats (so all you really need to do is write a small header before appending the output of vgReadPixels). It should be fairly easy - just search online for the BMP file format.

should i do the same things if i want to save in another format? (jpeg)

Hello,

I’m sorry to bother you for something that you could find trivial but I have a trouble with the function vgReadPixels :
I draw several Paths but when I use the fonction vgReadPixels, i have no data in my destination buffer (only 0).
I thought that it is because the function don’t use the correct drawing surface. Do you see any other reason that disabled the reading of my drawing surface.
I think I have to precise that I cannot use the EGL library.

For be more clear I give you my source code :


int main(int argc, char** argv)
{
	int i;
	const short WIDTH = 744;
	const short HEIGHT = 1052;
	const char* outName = "dump.tga";
    float   clearColor[4] = {1.0f,0.0f,1.0f,1.0f};
    VGPath  paths[NUM_PATHS];
    VGPaint paint;	

	/* Initialize */
    paint = vgCreatePaint();
    vgSetPaint(paint, VG_FILL_PATH);
	vgSeti(VG_FILL_RULE, VG_NON_ZERO);
	vgFinish();

    for(i=0;i<NUM_PATHS;i++)
    {
    	paths[i] = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, (unsigned int)VG_PATH_CAPABILITY_ALL);
		vgAppendPathData(paths[i], obj_paths[i].nCommands, (VGubyte*)obj_paths[i].cmds, (VGubyte*)obj_paths[i].floats);
		vgFinish();
    }
	
	/* Render */
    vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
    vgClear(0, 0, WIDTH, HEIGHT);
	vgFinish();

    for(i = 0; i < NUM_PATHS; i++)
    {
    	vgSetColor(paint, obj_paths[i].color | 255);
		vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
		vgLoadIdentity();
		vgScale(0.2f, 0.2f);
		vgMultMatrix(obj_paths[i].transform);
    	vgDrawPath(paths[i], VG_FILL_PATH);
		vgFinish();
		switch(vgGetError())
		{
			case VG_BAD_HANDLE_ERROR : 
				fprintf(stderr, "erreur : VG_BAD_HANDLE_ERROR
");
  				break;
		}
    }

	/* Save framebuffer to disk */
    VGubyte *dst;
		
    dst = malloc(WIDTH*HEIGHT*4*sizeof(VGubyte));
    vgReadPixels(dst, WIDTH *4* sizeof(VGubyte), VG_sARGB_8888, 0, 0, WIDTH, HEIGHT); 

	switch(vgGetError())
	{
		case VG_UNSUPPORTED_IMAGE_FORMAT_ERROR : 
			fprintf(stderr, "erreur : VG_UNSUPPORTED_IMAGE_FORMAT_ERROR
");
  			break;
	}

	for(i=0;i<WIDTH*HEIGHT;i++)
	{
		//dst[4*i]=255;     //A
		//dst[(4*i)+1]=255; //R
		//dst[(4*i)+2]=0;   //G
		//dst[(4*i)+3]=255; //B
		printf("[%d,%d,%d,%d]
",dst[4*i],dst[(4*i)+1],dst[(4*i)+2],dst[(4*i)+3]);
	}  
    
	if(!exportTGA(outName, WIDTH, HEIGHT, (VGuint*)dst))
		fprintf(stderr, "Failed to save framebuffer!
");

	/* Cleanup */
	vgDestroyPaint(paint);
	for(i = 0; i < NUM_PATHS; i++)
		vgDestroyPath(paths[i]);

    free(dst);
	return 0;
}