Solved

Help me before my Brain Explodes...

Posted on 2004-04-21
25
316 Views
Last Modified: 2010-04-05
Hi

    Please help; I’ve spent the last three nights getting completely lost with this problem.  I have the following code, which loads the image specified by CimageDir into a Timage component (strait off the pallet with only the visible set to false) The procedure then changes all the pixels with the colour specified in ColToChange to a colour specified in an array of colours.  So far whenever I have used this code it has worked wonderfully, and I had mainly forgotten about it until Monday when it started to play up... (I didn’t touch it…honest)

    Before I explain any more the input and output images for the procedure are available here www.davidbirch2.com/Hidden/Images.zip

    The procedure is called 6 times in the program, three with the first input image and 3 with the second input image.  The coltochange is ALWAYS clfushia (i.e. pink - see the images), the CImagedir specifies where the 2 images can be found and the changeTO changes every time so I should get a version of each of the input images in 3 different colours... (See outputs 1-3 to get the idea)

    The problem is that while the procedure works excellently for the first input image, the second image comes through completely unchanged (i.e. pink see outputs 4-6), and I have no idea why!!! None of the error messages are triggered!! I put a breakpoint on the line, which changes the colour. It was triggered for the first 3 outputs but not the last 3!!! ??? data in the variables is in the comments

procedure TeamColorPic(CImageDir,ColToChange: String; ChangeTo : integer);
Var                    //img dir  //clfushia         //1
  AW,AY: integer;
  CFrom,CTo: Tcolor;
Begin
   try
      (ImageForm.FindComponent('ColChanger') as TImage).Picture.LoadFromFile(CImageDir);
   except ShowMessage('Error loading Image'); end;

   try
      CFrom:= stringtocolor(ColToChange);  //16711935       clfushia
      CTo:= stringtocolor(TeamCols[ChangeTo]); //16711680   clblue
   except ShowMessage('Error loading colors'); end;

   AW:= -1;
   repeat
   AW:= AW+1;

      AY:= -1;
      repeat
      AY:= AY+1;

         If (ImageForm.FindComponent('ColChanger') as TImage).Canvas.Pixels[AW,AY] = CFrom then
         (ImageForm.FindComponent('ColChanger') as TImage).Canvas.Pixels[AW,AY]:= CTo;

      until AY= (ImageForm.FindComponent('ColChanger') as TImage).Picture.Width;

   until AW= (ImageForm.FindComponent('ColChanger') as TImage).Picture.Height;

   DeleteFile(Directorie+'\Temp\Images\Changer.bmp');

   (ImageForm.FindComponent('ColChanger') as TImage).Picture.SaveToFile(Directorie+'\Temp\Images\Changer.bmp');

end;

Please help, if you want any more information then I’ll happily supply it…If you have any idea what’s wrong (its probably going to be something stupid – it usually is…) pleas just tell me… If you know of a better way of doing the above then please say as I’m toughly lost

David

P>S>sorry for the low points, its all i have left @ the moment...
0
Comment
Question by:DavidBirch2dotCom
  • 9
  • 9
  • 3
  • +1
25 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10882026
It just happans that I'm doing very similary things at the moment.

try to replace

         If (ImageForm.FindComponent('ColChanger') as TImage).Canvas.Pixels[AW,AY] = CFrom then
         (ImageForm.FindComponent('ColChanger') as TImage).Canvas.Pixels[AW,AY]:= CTo;

with

         If (ImageForm.FindComponent('ColChanger') as TImage).Picture.Bitmap.Canvas.Pixels[AW,AY] = CFrom then
         (ImageForm.FindComponent('ColChanger') as TImage).Picture.Bitmap.Canvas.Pixels[AW,AY]:= CTo;

If it doesn't help let me know.
In fact I'm writing to new bitmap.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10882083
Can you email me what you have, so i can see this procedure in action - i've tried implementing it , but can't seem to figure out what you are doing by what you have provided. Zip it up and mail it to:

holmesshane AT charter DOT net
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10882158
mokule > nope the output is still pink.....

its crossed my mind - do i need to clear the bitmap or somthing?

shaneholmes> i'd rather not release the source - its a very large project, though im fairly sure this is where the error is...

David
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10882302
please download the images again... ive added some more

www.davidbirch2.com/Hidden/Images.zip

umm ok i messed up the input image (mainly cos im fed up wiv it ;) ) see input3 and it gave me output7 ????? - they mystery deepens.... looks like its got confused between the X and Y - but i have no idea why....

David
0
 
LVL 17

Expert Comment

by:mokule
ID: 10882336

Have You set

AutoSize := True

for the Image?
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10882398
ARGGG!!!!

its so blindingly obvious we all missed it.... I had the width and the height  round the wrong way !!!!!!! *headbuts the wall* and the reason i had never noticed it before is that the last program only used tiles (which are all square).... thanks for helping me see the obvious....

mokule> im improving my latest game http://www.davidbirch2.com/Games/Sub_Game.htm what r u up to? is it possible to get a refund for this question, so i have at least some points for future questions...

David
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10882536
David,

I downloaded the zip file, but I keep getting access violations for file not found. I tried having the images in both the image folder and in the main folder

BTW, have you ever taken a look at this:

http://www.gamemaker.nl/

Its a free download. Its easy, and if you understand basic delphi, you will understand this very well. Not only was it written in Delphi, but it uses the same concepts..
Look at all the other games created with it.

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10885117
Sure as long as he posts his correction, I dont mind....

Shane
0
 
LVL 17

Accepted Solution

by:
mokule earned 120 total points
ID: 10886936
Thanks kretzschmar :)
Maybe there is something in it. But I really don't feel to solve the real problem.

Regards
Marek
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10889485
Phew well I wasn’t expecting to have 7 posts waiting for me when I got home...

HE thank you kretzschmar how many female DAVIDS do u know? ;-p)

Ok mokule gets the points; I doubt I would have seen it without your help, thanks again

shanehomles > the different game maker packages simply do not offer the level of control I want for my games, there are also often royalty issues, I also want all my games to be fully modable which few if any game makers are... and also how many game makers are there which will let you develop a full RTS game? Besides I have already spent 3 months of spare time writing a game engine (14000 lines+) and the current game i'm on already has over 1500 lines... beside writing your own is much more fun as the above illustrates...

Thanks all

David
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10889522
>kretzschmar how many female DAVIDS do u know? ;-p)

hum, no one :-))
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10889526
"shanehomles > the different game maker packages simply do not offer the level of control I want for my games, there are also often royalty issues, I also want all my games to be fully modable which few if any game makers are... and also how many game makers are there which will let you develop a full RTS game? Besides I have already spent 3 months of spare time writing a game engine (14000 lines+) and the current game i'm on already has over 1500 lines... beside writing your own is much more fun as the above illustrates..."

I beg to differ,  The level of control is outstanding (you evidently didin't look at the games created with it).
Also, there are no royalty issues. It is fully modable - allowing for the use of Scripts, DLLS, external files, its just plain unlimited....
- but HEY it wasn't an answer, it was a suggestion - Good Luck!

Shane
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10889623
Shane > for my purposes custom built is the best option, i agree that in some circumstances game makers are very useful and will save time and produce better results!, i did look at the sample games but they were nothing like what i eventualy plan to create...

thanks anyway

David
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10889647
OK, well anyway, about my post above....

"I downloaded the zip file, but I keep getting access violations for file not found. I tried having the images in both the image folder and in the main folder"

Why am i getting this?


Shane
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10889785
Your trying to use the above code? Mainly because you don’t have the 2000 lines+ of backup and behind the scenes workings for this part of the game engine... Directorie is my own variable which is set on start to using the getcurrentdir function, TeamCols is an array of strings each holding a colour either in the format 'clblue' or $0000000 ect also you need to have the relevant folder structure in place, and (ImageForm.FindComponent('ColChanger') as TImage) means that the imageform needs to be set, you could also change this to form1 or whatever your form is called... and dont foreget to change the width and height around ;)  if your interesting the game engine I’m developing please contact me web at davidbirch2.com

Thanks

David
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10889835
No, i downlaoded your zip file and ran the executable, i never tried loading and running any code....

Shane
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10889938
you mean the game ? u need to unzip somewhere thenrun it , so it can load the graphics

David
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10889958
I did unzip it, as i stated above. I also unzipped the images. I tried having the images in the main folder and in a image\ folder

no luck, still wont run, throws access violations


Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10890013
Never mind.... I figured out what it was.... My winzip, had user folder names unchecked.

Shane
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10890058
the next release (in the next few days) will also have an installsheild version to get around this problem... the new release will feature high-scores table and 2 new enemy types as well as new and improved images.

David
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10890325
You can go to www.delphiforfun.org and get the code to my Simon game, which has a nice highscores unit.

http://www.delphiforfun.org/Programs/Simon.htm


BTW, wouldn't it be easier to have the images stored in a resource file. Your images are small.

You could also create multi-images of the subs depicting the state of damage, then use an integer value to track the state of damage - and call the appropriate image related to the damage.

Just a thought!

Shane
0
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 10890465
lol your too late ive already done the high scores :) yes those things would be nice but one of the key principles of my game are that they are modible without any special tools, just paint and notpad....  thinking about it, what you just described is pretty much what i do at the moment - just that the images are seperate so they are easier to modify... eventualy i might add damage to the ship, but then ive got to do some more images which is a pain...

thanks for your input

David
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

19 Experts available now in Live!

Get 1:1 Help Now