Thread View: rec.games.programmer
2 messages
2 total messages
Started by Brian Troxell
Sat, 08 Aug 1992 23:22
Image saving in MSC7.0
Author: Brian Troxell
Date: Sat, 08 Aug 1992 23:22
Date: Sat, 08 Aug 1992 23:22
25 lines
1397 bytes
1397 bytes
I am attempting to write my first graphics game, so forgive me if
this is a simple question.
I am using Microsoft C 7.0 on a 386SX. The basic thing I want to do is
to use getimage and putimage to move images around. The images are small
(20 pels by 20 pels), so speed is not a problem. However, I don't want
to create the images and then use getimage to get it. I would like to save
the image to a hard drive, then just read it in and putimage it on the
screen.
Any ideas on how to do this?
I tried the simple approach: usr fopen and fwrite and write out the data
stored by a pointer defined in a getimage call, then use fread and putimage
on the file. Putimage returns 0, but nothing gets displayed.
Any help, pointers, references, etc. would be greatly appreciated.
Thanks.
--
|~~\ rian 2000 Powers Fy Rd. | "I have no idea. What's it supposed
|--< _____ Suite 200 | to be?"
|__/ | Marietta, Ga 30067 | "A whinzer."
| roxell (404)933-7600 | "A _whinzer_?!"
Re: Image saving in MSC7.0
Author: Dixie Cup
Date: Sun, 09 Aug 1992 15:09
Date: Sun, 09 Aug 1992 15:09
59 lines
2594 bytes
2594 bytes
In article <485@audfax.audiofax.com> brian@audiofax.com (Brian Troxell) writes:
>I am attempting to write my first graphics game, so forgive me if
>this is a simple question.
>
>I am using Microsoft C 7.0 on a 386SX. The basic thing I want to do is
>to use getimage and putimage to move images around. The images are small
>(20 pels by 20 pels), so speed is not a problem. However, I don't want
>to create the images and then use getimage to get it. I would like to save
>the image to a hard drive, then just read it in and putimage it on the
>screen.
>
>Any ideas on how to do this?
>
>I tried the simple approach: usr fopen and fwrite and write out the data
>stored by a pointer defined in a getimage call, then use fread and putimage
>on the file. Putimage returns 0, but nothing gets displayed.
>
>Any help, pointers, references, etc. would be greatly appreciated.
Well, wrting to a file is easy, reading is a little trickier. I use
Borland C so I'm not sure if the same format will apply for reading.
But here goes:
void SaveImage(void *image, unsigned size){
FILE *imgfile = fopen("image","w");
fwrite(image, size, 1, imgfile);
fclose(imgfile);
}
You have to pass the size of the image that is returned by the imagesize
function. Now to read an image from a file if you already know the size
of the image is easy.
void ReadImage(void *image, unsigned size){
FILE *imgfile = fopen("image","r");
image = malloc(size);
fread(image, size, 1, imgfile);
fclose(imgfile);
}
If you don't already know the size ahead of time you can take a couple
of strategies. You can write the size at the beginning of the file and
then just read that first and then continue to read the image or you
can try to determine the size from the info in the image format. This
is pretty much what you would have to do to read the size from the image
format:
x = fgetc(imgfile) | (fgetc(imgfile) << 8);
y = fgetc(imgfile) | (fgetc(imgfile) << 8);
size = imagesize(0, 0, x, y);
image = malloc(size);
rewind(imgfile);
Then insert the ReadImage code.
Daniel
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads