Heyy
im a 12th grade student trying 2 put pictures in my cricket project
i have 2 display pics of all players
i have a code
but it works only for some pictures
at times it crashed down and pc shuts down
any1 has a proper code to display 256 color format in turbo ...
please help
im in dam bad need of help
thnx a lot

following is the code
please do implement changes f necessary
please help me

******************************************************
# include <iostream.h>
# include <conio.h>
# include <stdio.h>
# include <string.h>
# include <ctype.h>
# include <time.h>
# include <dos.h>
# include <graphics.h>
# include <stdlib.h>
# include <fstream.h>

//BitMap Structure

struct A
{
    char type[2];                 /* Magic identifier            */
    unsigned long size;                       /* File size in bytes          */
    unsigned short int reserved1, reserved2;
    unsigned long offset;                     /* Offset to image data, bytes */
};
A HEADER,HEADER1;

struct B
{
    unsigned long size;               /* Header size in bytes      */
    unsigned long width,height;                /* Width and height of image */
    unsigned short int planes;       /* Number of colour planes   */
    unsigned short int bits;         /* Bits per pixel            */
    unsigned long compression;        /* Compression type          */
    unsigned long imagesize;          /* Image size in bytes       */
    unsigned long xresolution,yresolution;     /* Pixels per meter          */
    unsigned long ncolours;           /* Number of colours         */
    unsigned long importantcolours;   /* Important colours         */
};
B INFOHEADER,INFOHEADER1;       //This Global Function is used for the resolution of the bitmap. You can set the return value either 1,2 or 3. For me 3 is the best combination.

huge DetectSvga()
{
   return 4;
}

void Show()
{
fstream File;       //Here you have to define the path of the bitmap file. Like according to this example i have to open one Board1.bmp file. So write you bitmap file path here.
int XCor=100,YCor=100;
File.open("ind.jpg",ios::in);
unsigned char Ch;
File.read((char*)&HEADER,14); //This is the header part of the Bitmap. It always looks like same. Don't change the content hear. The value remains 14 here.
File.read((char*)&INFOHEADER,40); //This is another part of the bitmap, here also the value remains same like 40 here.
unsigned int i;
char ColorBytes[4];
char*PaletteData;
PaletteData=new char[256*3];
if(PaletteData)//if memory allocated successfully
{
    //read color data
for(i=0;i<256;i++)
{
    File.read(ColorBytes,4);
    PaletteData[(int)(i*3+2)]=ColorBytes[0]>>2;
    PaletteData[(int)(i*3+1)]=ColorBytes[1]>>2;
    PaletteData[(int)(i*3+0)]=ColorBytes[2]>>2;
}
outp(0x03c8,0);      //tell DAC that data is coming
for(i=0;i<256*3;i++) //send data to SVGA DAC
{
    outp(0x03c9,PaletteData[i]);
}
delete[]PaletteData;
}
for(i=0;i<INFOHEADER.height;i++)       //This for loop is used to display the bitmap.
{
    for(int j=0;j<INFOHEADER.width;)
    {
        File.read(&Ch,1); // Here Ch reads the color of your bitmap.
        putpixel(XCor+j++,YCor+INFOHEADER.height-i-1,Ch); //XCor and YCor are the X and Y cordinates. It depends upon you.
    }
}
File.close();
}

void main()
{
int gd = DETECT, md, a;
installuserdriver("SVGA256",&DetectSvga);
initgraph(&gd,&md,"c:\\tc\\bgi"); //Path may be different in your computer.
Show();
getch();

}

Please remember to use code tags, there's a big button which says (Code) in the reply box now, so there's really no excuse for missing it other than a lack of effort.

Now some points about your code, your teacher shouldn't be making you use Turbo C++, it's outdated, and can be replaced by one of many free compilers available online. However as you're using graphics.h, I doubt you're going to bother changing. Unfortunately, this means helping you wont be easy, as there are no good programmers using Turbo C++ anymore.

void main() Don't use void main, it's bad practice, just use int main() and save yourself a few problems.

The thing is tht i have 2 use this compiler because of my BOARD
the cbse board wants students to use turbo c++/borland c++

since i need graphics ... i have 2 use it .... can u help by any chance !!
pleease

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.