4 Replies - 8775 Views - Last Post: 07 October 2008 - 01:51 PM Rate Topic: ****- 1 Votes

#1 vyiruskiller   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 14
  • Joined: 04-October 06

Using BMP images with C++

Post icon  Posted 06 October 2008 - 12:03 PM

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.

 #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)



Is This A Good Question/Topic? 0
  • +

Replies To: Using BMP images with C++

#2 AntiBNI   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 21-July 06

Re: Using BMP images with C++

Posted 06 October 2008 - 01:05 PM

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.
Was This Post Helpful? 0
  • +
  • -

#3 vyiruskiller   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 14
  • Joined: 04-October 06

Re: Using BMP images with C++

Posted 06 October 2008 - 02:16 PM

View Postvyiruskiller, on 6 Oct, 2008 - 12:03 PM, said:

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.

Was This Post Helpful? 0
  • +
  • -

#4 vyiruskiller   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 14
  • Joined: 04-October 06

Re: Using BMP images with C++

Posted 07 October 2008 - 01:12 PM

View PostAntiBNI, on 6 Oct, 2008 - 01:05 PM, said:

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

Was This Post Helpful? 0
  • +
  • -

#5 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 628
  • Joined: 24-July 08

Re: Using BMP images with C++

Posted 07 October 2008 - 01:51 PM

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1