Solved

getimage,putimage question

Posted on 1998-05-22
22
774 Views
Last Modified: 2008-02-01
Hello experts!
does anyone know of a way i can put 2 diffrent pictures in the memory?
I tried using 2 diffrent pointers, but it still doesnt work.
and if there isnt a way of doing this, so can anyone advise me of an alternative, instead of drawing the pictures over and over?

0
Comment
Question by:yolis
  • 10
  • 5
  • 3
  • +2
22 Comments
 
LVL 1

Expert Comment

by:cph
ID: 1164548
Do you mean that you allocated 2 pointers and set each one of them to a picture?
Could you give more details...
0
 

Author Comment

by:yolis
ID: 1164549
ok, what i made a cute little program, that saves a drawing in a square of 25*25, at a 640*480 mode.
the square is an int pic[25][25]. if value is 1 then show a dot, if value is 0, then no dot.
the int is being saved in a binary to a file.
I did this program for another program of mine, which i need to put pictures at the size 25*25, till now there was only  one picture, so what i did, is in my program, i read the contents of the binary file, to another int pix[25][25].
and i showed it in the screen (using a for) and then i save it in the memory,
size=imagesize(0,0,25,25);
buffer=new char(size);
getimage(0,0,25,25,buffer);

and then, whenever i needed, i just took it from the memory, using putimage.

but now, i want to use 2 pictures, or more...
so, i tried using 2 diffrent buffers, one for each image, but it didnt work.
Can you now help me?!
thanks!


0
 
LVL 23

Expert Comment

by:chensu
ID: 1164550
size=imagesize(0,0,25,25);
buffer1=new char(size);
getimage(0,0,25,25,buffer1);

size=imagesize(0,0,25,25);
buffer2=new char(size);
getimage(0,0,25,25,buffer2);

buffer1 and buffer2 point to different memory area. It should work.
0
 

Author Comment

by:yolis
ID: 1164551
Look, I wrote in my comment before that i tried it with 2 diffrent buffers...
it doesnt work!, Dont ask my way, my logic sais also that it should point to diffrent places.
what happens is that the second picture.. (the one that i getimage it secondly) is working, and the first image looks like the second but distorted(changes colors, and there are some lines that should not have been there..).

well, can anyone answer me? please?

0
 
LVL 3

Expert Comment

by:Norbert
ID: 1164552
Working with 2 pointer MUST work !!!
There must be a bug within your code and nobody can find a solution without seeing your code.
0
 

Author Comment

by:yolis
ID: 1164553
Here is the code that i tried to use for 2 diffrent pictures:


void *buffer1,*buffer2;
unsigned size;
void set_enemy()
{
  int i,i2,r,l;
  int pic2[25][25];
  int pic[25][25];
  ifstream f("pic.dat");
  f.read((unsigned char *)&pic,sizeof(pic));
  f.close();
  f.open("pic2.dat");
  f.read((unsigned char *)&pic2,sizeof(pic2));
  f.close();

  for(i=1;i<=E;i++)
  {
  if(i<=32) { a[i-1].x=i*55-1260; a[i-1].y=140; }
  if(i<=24) { a[i-1].x=i*55-820; a[i-1].y=100; }
  if(i<=16) { a[i-1].x=i*55-380; a[i-1].y=60; }
  if(i<=8) { a[i-1].x=i*55+60; a[i-1].y=20; }
  a[i-1].n=i-1;
  a[i-1].f=0;
  if(i>=25) a[i-1].f=1;
  setfillstyle(1,0);
  }
  bar3d(0, 0, 25, 25,0,1);
  for(r=0;r<25;r++)
  for(l=0;l<25;l++)
  if (pic[r][l]==1) putpixel(r,l,14);
  size=imagesize(0,0,25,25);
  buffer1=new char(size);
  getimage(0,0,25,25,buffer1);
  cleardevice();
  for(r=0;r<25;r++)
  for(l=0;l<25;l++)
  if (pic2[r][l]==1) putpixel(r,l,4);
  size=imagesize(0,0,25,25);
  buffer2=new char(size);
  getimage(0,0,25,25,buffer2);
}

0
 
LVL 1

Expert Comment

by:cph
ID: 1164554
your Buffers variable should be of type CHAR
0
 

Author Comment

by:yolis
ID: 1164555
it still isnt working when i put them at type char..

0
 
LVL 3

Expert Comment

by:Norbert
ID: 1164556
What happens ? are the pictures mixed or happens something
mystic ?
0
 

Author Comment

by:yolis
ID: 1164557
the first image i put in memory looks, like the second image, only with diffrent colors, and there are also added a few lines that should not have been there..

0
 
LVL 3

Expert Comment

by:Norbert
ID: 1164558
only thinking...
How different the two images are originaly ?
the only difference I can see is
 if (pic[r][l]==1) putpixel(r,l,14);
 if (pic2[r][l]==1) putpixel(r,l,4);
does both files realy exist and have different images?
you did not check number of bytes read
does the first image looks like the second or does the second image looks like the first ?
what does cleardevice
I can not find information about cleardevice in VC++ 5.0
so what enviroment do you use dos, unix, windows ... ?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:cph
ID: 1164559
Letme guess, he is using dos and I think the bgi library (Borland C++ isn't it?)...
0
 

Author Comment

by:yolis
ID: 1164560
correct cph!
i am using borland c++, for DOS not windows..., using the bgi library..

yes, the both files exists, and have diffrent images in them.
the first image looks like the second.
cleardevice() is like clrscr() but for a graphics view.
I hope that now you can answer me..


0
 
LVL 1

Expert Comment

by:cph
ID: 1164561
try to change the type of pic. Change it to an unsigned char and remove the casting in the read statement.

If it doesn't work could send more of the code...
0
 

Author Comment

by:yolis
ID: 1164562
looking there is something that you dont understand...
I can view the pictures on screen as long as i load it from the file and use a loop like the for that i have in the beginning...
but the problem is to put it in memory and then to take it from the memory..
I know, that if i take the pictures from memory it will be muth faster than using a loop over and over...
Ok?
why dont someone of you will try to put 2 pictures in the memory, and the to output them in to the screen, if it works, please tell me how..

thanks alot alot,   Yoli.

0
 
LVL 2

Expert Comment

by:kinkajou
ID: 1164563
What exactly do you mean "putting two pictures into memory"? It seems to me that both a file and a char array are different types of memory that your pictures exist in. It also sounds like you have a simple case of corrupted memory. Trymaking the two picture buffers, pic and pic2, globals. Also, you may want to try allocating the buffers. Have you debugged the application to see if you pic and pic2 pointers are corrupting? Have you debugged the appilcation to watch the memory of those picture arrays to see if they are corrupting?
0
 

Author Comment

by:yolis
ID: 1164564
when i said putting two pictures into the memory, i ment using two diffrent pictures with the command getimage..
thats all..
and what do you mean corrupt memory? how do i check it? how do i watch the memory to see if it is corrupted?

0
 
LVL 1

Expert Comment

by:cph
ID: 1164565
You run the Borland's debugger (I should say Inprise, never mind ...) check the value in the first buffer (pic) adn then once you read the second picture in the buffer pic2 check that pic was not affect by the loading of pic2. Also check the content of pic2.
Could you send the code, so that we can try to run it and maybe we will find out the problem...
0
 
LVL 2

Expert Comment

by:kinkajou
ID: 1164566
You check your corrupt memory by debugging it. One method of debugging would be to print out and check each byte of your images in comparision to the memory buffers, in your case pic and pic2. If there are any inequalities in the comparison, you have corruption.
0
 
LVL 2

Accepted Solution

by:
kinkajou earned 50 total points
ID: 1164567
Yolis,

I suggest not using the putimage() and getimage() functions and allocating you own memory for the pictures. Displaying the image starts with understanding the linear video buffer that begins at address 0xA0000000, calculating the offset or x/y position in the video buffer and writting you pixels for each line of your image on the display video. You could create a routine/function to do this work with little effort. You could also pick up an Assembler book and use the INT 10h functions to display. DOS games programming books usually begin with a chapter detailing DOS displaying for buffered video data. A book I've used with success is "Tricks of the Game Programming Gurus" by SAMS publishing. One of the first chapters discusses all of the assembly and displaying theory you'll need and has example code using assember and C. I suggest using your own functions and allocing the memory so that you can get away from what sounds like a compilation error. While working at the university, we saw Borland C compilers do lots of crazy things that suggested compilation problems. We did not see the same sort of problems with Watcom C or Microsoft C compilers.
0
 

Author Comment

by:yolis
ID: 1164568
I would like to THANK EVERYONE WHO SHARED THIS PROBLEM WITH ME!

however, I finally managed to overcome my problem by using malloc(), instead of new()

well, bye!


0
 

Author Comment

by:yolis
ID: 1164569
I would like to THANK EVERYONE WHO SHARED THIS PROBLEM WITH ME!

however, I finally managed to overcome my problem by using malloc(), instead of new()

well, bye!


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now