GIDForums

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Jan-2008, 01:18
hemadri.k hemadri.k is offline
New Member
 
Join Date: Jan 2008
Location: noida , India
Posts: 3
hemadri.k is on a distinguished road

Save screen as .bmp image


hi all,
I created a window and i am able to do free hand draw on the window using mouse by handling mouse events.
Now i want to save the image on the window as bmp image file
please give me a solution how to get the pixel buffer from the window.

waiting for a reply.....
  #2  
Old 22-Jan-2008, 23:20
hemadri.k hemadri.k is offline
New Member
 
Join Date: Jan 2008
Location: noida , India
Posts: 3
hemadri.k is on a distinguished road

Re: save screen as bmp image


hi all,

i found the solution for this
use fl_read_image() function to read the pixel data to a buffer.
and write your own bmpfile creator code (writing the code for bmp file creation is easy)

if any possible solutions are there please post them
  #3  
Old 24-Jan-2008, 21:35
ERetana ERetana is offline
New Member
 
Join Date: Jan 2008
Posts: 1
ERetana is on a distinguished road

Re: Save screen as .bmp image


Hi

Could you post your code ?

I need to exactly the same thing in my program.
  #4  
Old 24-Jan-2008, 21:53
hemadri.k hemadri.k is offline
New Member
 
Join Date: Jan 2008
Location: noida , India
Posts: 3
hemadri.k is on a distinguished road

Re: Save screen as .bmp image


hi ERetana,

i thought of posting the code before itself but the code i wrote is very limited one ,any way i am posting my code

************************************************** ******
CPP / C++ / C Code:
unsigned char p[500 * 150 *3];
#pragma pack(1)
struct HEADER
{
   unsigned char type1;                 /* Magic identifier            */
   unsigned char type2;
   unsigned int size;                       /* File size in bytes          */
   unsigned short int reserved1, reserved2;
   unsigned int offset;                     /* Offset to image data, bytes */
};
#pragma pack()
typedef struct HEADER BMPHEADER;
struct INFOHEADER{
   unsigned int size;               /* Header size in bytes      */
   int width,height;                /* Width and height of image */
   unsigned short int planes;       /* Number of colour planes   */
   unsigned short int bits;         /* Bits per pixel            */
   unsigned int compression;        /* Compression type          */
   unsigned int imagesize;          /* Image size in bytes       */
   int xresolution,yresolution;     /* Pixels per meter          */
   unsigned int ncolours;           /* Number of colours         */
   unsigned int importantcolours;   /* Important colours         */
};
typedef struct INFOHEADER BMPINFOHEADER;


void bmpcreate(const char * name)
{
        BMPHEADER bmpheader;
        BMPINFOHEADER bmpinfoheader;
        bmpheader.type1 = 0x42;
        bmpheader.type2 = 0x4D;
        bmpheader.size = sizeof(p)+54;
        bmpheader.offset = 54;

        bmpinfoheader.size = 40;
        bmpinfoheader.width = 500;
        bmpinfoheader.height = 150;
        bmpinfoheader.planes = 1;
        bmpinfoheader.bits = 24;
        bmpinfoheader.compression = 0;
        bmpinfoheader.imagesize = sizeof(p);
        bmpinfoheader.xresolution = 0;
        bmpinfoheader.yresolution = 0;
        bmpinfoheader.ncolours = 0;
        bmpinfoheader.importantcolours = 0;

        FILE *fstream;
        fstream = fopen(name,"wb");
        fwrite(&bmpheader,sizeof(BMPHEADER),1,fstream);
        fwrite(&bmpinfoheader,sizeof(BMPINFOHEADER),1,fstream);
        fwrite(p,sizeof(p),1,fstream);
        fclose(fstream);
}
************************************************** ******

this is highly hardcoded one manually set width to 500, height to 150, depth to 24 bits.

the image u get is a inverted image

i wrote this code to check screen shot is working or not its working fine for me


use this function call to store the pixel buffer to 'p'
fl_read_image(p,0,0,500,150,0);
where u call this function is up to your logic

after this call function
bmpcreate(const char *name);


with regards

hemadri.k
Last edited by cable_guy_67 : 31-Jan-2008 at 04:51. Reason: Please surround your C++ code with [cpp] your code [/cpp]
  #5  
Old 13-Mar-2008, 10:55
transfrank transfrank is offline
Junior Member
 
Join Date: Aug 2007
Posts: 53
transfrank is on a distinguished road

Re: Save screen as .bmp image


Did you manage to get it not inverted? I am trying to do this too. I was thinking about using libgd which would allow to write files of several formats.
Frank
  #6  
Old 16-Mar-2008, 15:52
transfrank transfrank is offline
Junior Member
 
Join Date: Aug 2007
Posts: 53
transfrank is on a distinguished road

Re: Save screen as .bmp image


On windows, the red and blue got inverted. Anyway, I got it to flip vertically.
 

Recent GIDBlogNon-US citizens serving in the military by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image onto JFrame tedds Java Forum 8 25-Oct-2007 20:04
need help with a console menu system BullBuchanan CPP / C++ Forum 6 20-Aug-2006 14:46
GIM gidedit - a fltk fluid resize project cable_guy_67 FLTK Forum 2 01-Jun-2005 15:00
Checking source codes of image, audio and video files onauc C Programming Language 5 26-Feb-2005 21:47
send pc image to tv screen?! Hood Computer Hardware Forum 5 05-May-2004 11:51

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:44.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.