View Full Version : graphics.h under Turbo C

10-21-2001, 12:51 PM

Ok,sorry if this is too DOS-centered..

This may sound stupid ..but is there any way i can save images drawn in graphics mode as a real image file..
which can be accesed by other programs in graphics mode..

( being accessed by something like PAINT is too much to ask..)

Also ,can I define my own custom colours..If yes,how?!


10-21-2001, 01:23 PM
> but is there any way i can save images drawn in graphics mode as a real image file
The getimage function would be a place to start.

> Also ,can I define my own custom colours..If yes,how?
Try the setpalette function
There seem to be several to choose from.

Open the graphics.h file in a text editor, and read the manual page for each function.

10-22-2001, 07:31 AM
If u want to save it as BMP or something, u need to study header for the extension.
And save the file according to that.

10-22-2001, 01:26 PM

Ok, i should have specified while asking..sorry!

Actually,using getimage() saves the image in a block of memory ..
Now,as this data is stored in the memory whose starting point is known to me,can i save this image in the same way in the file?

Also,as the above user said,how do i do that?!

And..setpalette() just changes the value of the colour you specify to one of the existing colours..I want to assign it a new colour,which is not part of the existing palette..!

can i define such a colour?

Please help!

11-06-2001, 12:38 AM
The graphics.h in Turbo C/C++ uses BGI graphics. The drivers for color modes higher than 16 colors are very difficult to find and won't run on most computers.
My suggestion is to write your own graphics library. First you'll have to learn the MCGA 300x200x256 mode. It supports 256 different colors.
On the other hand, in TC/TC++ there ARE only 16 colors, you can't define a new color, hence, only use these 16 colors. You can only change the position of these 16 colors in the palette.

To get the best tutorials on MCGA mode, see the Links Section of this site.

You can also find information on you to read in a 256 colors .bmp file in DOS in the links section. Proceeding in the opposite direction will enable you to save your own graphics into PAINT's .bmp files.

11-06-2001, 12:42 AM
Ok, sorry, incomplete answer

If you just want to save your 16-color graphics obtained through getimage...

You can do so, by sending all the data to a binary-mode file...through fwrite....

11-06-2001, 05:09 PM
Well, you could just spin up your own format. Like, use a hex value between 0 and F to stand for each of the 16 different colors.

To make an image, just write a loop that goes to each pixel and reads what the color is. Dump it into a file.

To display your images, just open the file, and make a loop that reads each hex value and writes the respective color of pixel to the screen.

If you want it to be supported by other image viewers, you could check out an archive called bgi2bmp. I'm sure a simple search on google would locate it.

11-22-2001, 05:17 AM

I do a have a bgi driver that sets to 256 colors in dos and high res. Tell me if u need it. I also have the source code ( in assembly ) for displaying bmp files. You could use it for saving also.
Tell me if you need it.