How to use Bitmap in Turbo C++

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: How to use Bitmap in Turbo C++

  1. #1
    Join Date
    Jul 2007

    Thumbs up How to use Bitmap in Turbo C++

    This simple program explain you about how to use BitMap in Turbo C++.

    NOTE : Before Running this program you have to copy one file in your "bgi" directory. That file either you have to download from the net or i will provide you. The file name is "SVGA256.BGI". Copy this file at your " tc\bgi\ ". Your tc path. There is no attachmet procedure thats why i am not able to attach this file. If you need this file send me the mail address, through this forum.

    1) You have to use the BitMap structure, there is no need to change anything in this structure. Just copy this structure in one of the .cpp file like "BitMap.cpp".
    //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 */
    extern 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         */
    2) In the main file i mean the file which contain the "main" function write this code.

    //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 3;             
    void main()
        int gd = DETECT, md, a;  
        initgraph(&gd,&md,"c:\\tc\\bgi"); //Path may be different in your computer.
    //Suppose you have one show function which read the bitmap from the disk. Then this show function looks like this
    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.
    	unsigned char Ch;
*)&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.
*)&INFOHEADER,40); //This is another part of the bitmap, here also the value remains same like 40 here.
    	unsigned int i;
    	char ColorBytes[4];
    	PaletteData=new char[256*3];
    	if(PaletteData)//if memory allocated successfully
    		//read color data
    		outp(0x03c8,0);      //tell DAC that data is coming
    		for(i=0;i<256*3;i++) //send data to SVGA DAC
    	for(i=0;i<INFOHEADER.height;i++)       //This for loop is used to display the bitmap.
    	  for(int j=0;j<INFOHEADER.width;)
    		{,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.
    //Another way to display the Bitmap is. Suppose i have another Show1() Function.
    void Show1()
         Char Ch;
        fstream File;"d:\\Chess\\Bitmaps\\KingA.bmp",ios::in);
       File.seekg(54,ios::beg);   //Its remains same. Means value always remains 54
       File.seekg(256*4,ios::cur); //Its remains same means value always remain 256*4.
    		for(int i=0;i<40;i++) //Here 40 shows the height of the bitmap. It may be differ it depends upon the size of your bitmap.
    			for(int j=0;j<36;j++) //Here 36 shows the width of the bitmap. It may be differ it depends upon the size of your bitmap.
    			{,1); //Here Ch is the character which reads the color of your bitmap.
    				putpixel(this->XCor+j,this->YCor+39-i ,Ch);
    Thanks and Regards


  2. #2
    Join Date
    Aug 2007
    I Run your program but doesn't work properly.
    help me! my graphic card is vga and demo shows EGAVGA MODE FOR IT .

  3. #3
    Join Date
    May 2007
    How about using bitmap in Visual Studion 2005 Service Pack 1 ?


  4. #4
    Join Date
    Dec 2003
    VS natively supports bitmaps, just use the built in gui tools / etc.

  5. #5
    Join Date
    May 2007
    I need to step by step to uses it in VS.

    Sorry for my stupidity.

    Thanks for your help.

  6. #6
    Join Date
    Apr 2007
    Have you tried searching for a tutorial on the internet? There are plenty.

    You could also just tinker with resources yourself. You are your own best teacher...

Similar Threads

  1. c++ class
    By martin in forum .NET
    Replies: 1
    Last Post: 09-05-2002, 09:46 PM
  2. How to place a API drawn bitmap in a stdOle.stdPicture
    By Peter Jonsson in forum VB Classic
    Replies: 4
    Last Post: 11-13-2001, 05:16 AM
  3. How to place a API drawn bitmap in a stdOle.stdPicture
    By Peter Jonsson in forum VB Classic
    Replies: 0
    Last Post: 11-12-2001, 09:18 AM
  4. Check out Turbo XML: Free trial download
    By Extensibility in forum web.announcements
    Replies: 0
    Last Post: 07-20-2000, 06:20 PM
  5. Check out Turbo XML
    By Sales in forum xml.announcements
    Replies: 0
    Last Post: 07-20-2000, 06:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center