Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,107 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,202 people online right now. Registration is fast and FREE... Join Now!




Using BMP images with C++

 
Reply to this topicStart new topic

Using BMP images with C++

Rating  4
vyiruskiller
post 6 Oct, 2008 - 11:03 AM
Post #1


New D.I.C Head

*
Joined: 4 Oct, 2006
Posts: 14


My Contributions


I am working on a project in TC with Bitmap images that should be moving on the screen when the user runs the program.
The problem I am having with this code is that i cannot see the full images i am using in the program (in other words, i would like the user to know what image he/she is viewing on the screen). Can someone help me please.

CODE
#include<graphics.h>
#include <stdlib.h>
#include<string.h>
#include <process.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>

#include<alloc.h>
#define C 10
#define F 2
#define T 15

FILE *f;

class Vwindow
{
void far *p;
int x;
int y;
int xf;
int yf;
public:
void LFree();
void init(int xx, int yy, int xxf, int yyf);
void capture();
void show();
void Imagen();
void Put_image();
};

void Vwindow::init(int xx, int yy, int xxf, int yyf)
{
x=xx;
y=yy;
yf=yyf;
xf=xxf;
}
void Vwindow::Imagen() {// function for my bmp image
int gd=DETECT,gm;
  int y=0,x=0;
  unsigned char bit1,bit2,bit;
  //initgraph(&gd,&gm,"C:\\tc\\bgi");

  f=fopen("pic.bmp","r");
  fseek(f,0x76,0);
  while(!feof(f))
  {
    bit=fgetc(f);
    bit1=bit>>4;
    bit2=(bit<<4)>>4;
    putpixel(x++,y,bit1);
    putpixel(x++,y,bit2);
    if (x>=xf)
    {
      x=0;y++;
    }

    }
    }

void Vwindow::capture()
{
  unsigned tsize;
  tsize=imagesize(x-3,y-3,xf+3,yf+3);
  if ((p = farmalloc(tsize)) == NULL)
    {
      outtextxy(10,10,"No memory..!");
    }
    else
        {
        getimage(x,y,xf,yf,p);
        }
}
void Vwindow::Put_image()
{
putimage(x,y,p,1);
}
void Vwindow::LFree()//free
{
farfree(p);
}

void Start_GMode();//START GRAPHIC MODE
void main()
{

int x=1;
int y=1;
int xf=42;
int yf=73;
Vwindow vn;
Start_GMode();
vn.init(x,y,xf,yf);
vn.Imagen();
vn.capture();
cleardevice();
outtextxy(10,1,"Hello World");
outtextxy(10,60,"Hello world");
outtextxy(10,110,"Hello World");
while(x<=251)
{
vn.init(x,y,xf,yf);
vn.Put_image();
delay(100);
vn.Put_image();
    if(x==251)
      {
          if(y<=101)
        {
       x=1;
    y+=50;
        }
      }
x+=10;

}

getch();
vn.LFree();
closegraph();

}


void Start_GMode()

{
/* request auto detection */
   int gdriver = DETECT, gmode, errorcode;

   /* initialize graphics mode */
   initgraph(&gdriver, &gmode, "t:\\tc\\bgi");

   /* read result of initialization */
   errorcode = graphresult();

   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);             /* return with error code */

   }
}


Attached File(s)
Attached File  project.zip ( 11.87k ) Number of downloads: 7
User is offlineProfile CardPM

Go to the top of the page

AntiBNI
post 6 Oct, 2008 - 12:05 PM
Post #2


D.I.C Head

**
Joined: 21 Jul, 2006
Posts: 52


My Contributions


I would recommend GDI++ for this animation type of projects.

Or if you want to go a step further for maybe a little more animation/3D kick to it go with OpenGL or DirectX.

As using other methods is a bit more trouble sum as you will have to deal with all sort of situations like flickering images,half drawn images,un-drawn background,etc.


I am making an app that will also use a lot of animation and im going with DirectX(still learning),as it will use a lot of animation features such as cover flow,interactive GUI,and more.
User is offlineProfile CardPM

Go to the top of the page

vyiruskiller
post 6 Oct, 2008 - 01:16 PM
Post #3


New D.I.C Head

*
Joined: 4 Oct, 2006
Posts: 14


My Contributions


QUOTE(vyiruskiller @ 6 Oct, 2008 - 12:03 PM) *

Ok. Actually i was thinking the same as you did. I asked my teacher if i can do it in another langauage since TC is a little complicated. But he told me no. We are currently programming in TC. That's why i am trying to use BMP images with TC.

User is offlineProfile CardPM

Go to the top of the page

vyiruskiller
post 7 Oct, 2008 - 12:12 PM
Post #4


New D.I.C Head

*
Joined: 4 Oct, 2006
Posts: 14


My Contributions


QUOTE(AntiBNI @ 6 Oct, 2008 - 01:05 PM) *

Can someone help me please with this code. I cannot view the image in which i am using in this program. As the code shows, I am trying to use a bmp image in TC with movements.
Can someone explain to me what i have wrong in my code or what i am missing please. Thanks you

User is offlineProfile CardPM

Go to the top of the page

UG Cyber
post 7 Oct, 2008 - 12:51 PM
Post #5


D.I.C Head

**
Joined: 24 Jul, 2008
Posts: 184



Thanked 3 times
My Contributions


1) Dont put your message in quote boxes.
2) To make it simple, use a compilier with RAD (Rapid Application Development).

Such as Visual C++, Borland (Unless you want it to work on other computers), ect...Just google for one.

It will allow you to put a BMP image on it and you can move it in your code or flash several pictures to make it look like an animation.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 09:33AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month