Results 1 to 4 of 4

Thread: Save image code from Desktop

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    2

    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!

  2. #2
    Senior Member
    Join Date
    Feb 2006
    Posts
    115

    Re: Save image code from Desktop

    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.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    2

    Re: Save image code from Desktop

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

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    1

    Re: Save image code from Desktop

    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 :
    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\n");
      				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\n");
      			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]\n",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!\n");
     
    	/* Cleanup */
    	vgDestroyPaint(paint);
    	for(i = 0; i < NUM_PATHS; i++)
    		vgDestroyPath(paths[i]);
     
        free(dst);
    	return 0;
    }

Similar Threads

  1. eglCopyBuffers() issue. How to save a copy of the image disp
    By tantissimo in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 05-29-2012, 04:00 AM
  2. save statemachine
    By cityhunter in forum Suggestions for the next OpenML revision
    Replies: 0
    Last Post: 06-19-2002, 01:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •