jimbopp
asked on
Images
I have 52 seperate pictures of cards which I want to use game. Is it possible to incorporate them in to a resorce file and then acces them from there, as it would be very messy having them all as seperate objects on my form.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Look at http://delphi.about.com/compute/delphi/library/weekly/aa113099a.htm
As TOndrej say u can use ImageList component.
Abdelghani
Abdelghani
Create a textfile with the contents between these two lines:
-------------------------- ---------- ---------- ---------- ----
CARD1 BITMAP "Card1.bmp"
CARD2 BITMAP "Card2.bmp"
CARD3 BITMAP "Card3.bmp"
CARD4 BITMAP "Card4.bmp"
CARD5 BITMAP "Card5.bmp"
-------------------------- ---------- ---------- ---------- ----
And continue this way for all your bitmaps... Save it as YourFile.RC and compile it with the Resource compiler. This is called BCR32.EXE and can be found in the Delphi BIN folder. It's a commandline tool, so start it like this:
C:\Borland\Delphi5\Bin\brc 32 YourFile.RC
This action will result in a file called YourFile.RES which needs to be connected to your project. Add
{$R YourFile.RES}
somewhere to your project.
Now, to use this do something like this:
var
FBitmap: TBitmap;
begin
FBitmap := TBitmap.Create;
FBitmap.LoadFromResourceNa me(HInstan ce, 'BITMAP_1');
Canvas.Draw(0, 0, FBitmap);
FBitmap.Free;
end;
That should be it...
--------------------------
CARD1 BITMAP "Card1.bmp"
CARD2 BITMAP "Card2.bmp"
CARD3 BITMAP "Card3.bmp"
CARD4 BITMAP "Card4.bmp"
CARD5 BITMAP "Card5.bmp"
--------------------------
And continue this way for all your bitmaps... Save it as YourFile.RC and compile it with the Resource compiler. This is called BCR32.EXE and can be found in the Delphi BIN folder. It's a commandline tool, so start it like this:
C:\Borland\Delphi5\Bin\brc
This action will result in a file called YourFile.RES which needs to be connected to your project. Add
{$R YourFile.RES}
somewhere to your project.
Now, to use this do something like this:
var
FBitmap: TBitmap;
begin
FBitmap := TBitmap.Create;
FBitmap.LoadFromResourceNa
Canvas.Draw(0, 0, FBitmap);
FBitmap.Free;
end;
That should be it...
Or put all in a dll file .
or deliver also a pen,
so that the user can paint self the card
on the monitor
just kidding :-))
so that the user can paint self the card
on the monitor
just kidding :-))
Hi,
You can load these images into a resource file and access them from there OR
you can load the images into an array on startup of the program. If you do this, the images must reside on your drive in a specific folder and your program should point to this folder to load the images into the array. You can then access the images from the array.
If you load the images into a resource file, you have to get and external program to create resources of greater then 256 colours if that is what you require, Delphi's resource editor only has the capablity of handling resources of 256 Colours.
Both can be easily done.
USING A RESOURSE FILE.
Create the image using a resource editor and make the image part of the resourse file of the program
global variable declaration
var
Bmp : TBitmap;
procedure TForm1.CreateBmp(Sender : TObject);
var
TempString : PChar;
begin
TempString := PChar('BitmapName'); Bmp := TBitmap.Create;
Bmp.Handle := LoadBitmap(HInstance, TempString);
LoadFromResourceName(HInst ance, TempString);
end;
procedure TForm1.LoadFromResourceNam e(Instance : THandle; const ResName : String);
begin
Image1.Picture.Assign(Bmp) ;
end;
end;
Hope this helps
Regards
TAZI
You can load these images into a resource file and access them from there OR
you can load the images into an array on startup of the program. If you do this, the images must reside on your drive in a specific folder and your program should point to this folder to load the images into the array. You can then access the images from the array.
If you load the images into a resource file, you have to get and external program to create resources of greater then 256 colours if that is what you require, Delphi's resource editor only has the capablity of handling resources of 256 Colours.
Both can be easily done.
USING A RESOURSE FILE.
Create the image using a resource editor and make the image part of the resourse file of the program
global variable declaration
var
Bmp : TBitmap;
procedure TForm1.CreateBmp(Sender : TObject);
var
TempString : PChar;
begin
TempString := PChar('BitmapName'); Bmp := TBitmap.Create;
Bmp.Handle := LoadBitmap(HInstance, TempString);
LoadFromResourceName(HInst
end;
procedure TForm1.LoadFromResourceNam
begin
Image1.Picture.Assign(Bmp)
end;
end;
Hope this helps
Regards
TAZI
I think putting them all in a TImageList would be much easier to deal with.
TAZI? Didn't I say something similar already? Besides, I like Bitmap.LoadFromResource(HI nstance, 'BitmapName') better...
In stead of a TImageList you could create an array[0..51] of TBitmap and use it to store the cards from the resource. Something like this:
{Global}
var
Cards: array[0..51] of TBitmap;
var
I:Integer;
begin
for I := Low(Cards) to High(Cards) do begin
Cards[I] := TBitmap.Create;
Cards[I].LoadFromResource( HInstance, Format('Card%d', [I+1]));
end;
end;
This results in an array of bitmaps that you can use...
What is better? A TImageList or an array of Images from the resource? I don't think it matters much, but I would prefer to use the array, not an ImageList...
In stead of a TImageList you could create an array[0..51] of TBitmap and use it to store the cards from the resource. Something like this:
{Global}
var
Cards: array[0..51] of TBitmap;
var
I:Integer;
begin
for I := Low(Cards) to High(Cards) do begin
Cards[I] := TBitmap.Create;
Cards[I].LoadFromResource(
end;
end;
This results in an array of bitmaps that you can use...
What is better? A TImageList or an array of Images from the resource? I don't think it matters much, but I would prefer to use the array, not an ImageList...
Greetings.
This question is still open today, perhaps it was overlooked or just lost in the volumes. Please return to this question to update it with comments if more information is needed to get your solution. If you've been helped by the participating expert(s), you may just convert their comment to the accepted answer and then grade and close. If an answer has ever been proposed you may not have this option to accept the comment as answer, if that is the case, ask the specific expert you wish to award to post an answer. This benefits others who then search our PAQ for just this solution, and rewards the experts who have provided information. A win/win scenario. Please DO NOT accept this comment as an answer, it is merely a reminder.
If you wish to award multiple participants, you can do so by creating a zero point question in the Community Support topic area, include this link and tell them which experts you'd like to award what amounts. If you'd like to delete this question, use the same process as above, but explain why you think it should be deleted. Here is the Community Support link: https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
You can always click on your profile to see all your open questions, in the event you also have other open items to be resolved. If your number of Questions Asked is not equal to the number of Answers Graded, choose to VIEW question history, and you'll quickly be able to navigate to your open items to close them as well.
I've had excellent help from experts-exchange through the years and find the real key to getting what I need is to remain active in all my questions, responding with results to suggestions until my solution is found, and recommend that highly.
Thank you very much for your responsiveness, it is very much appreciated.
":0) Asta
P.S. Some of the older questions from last year are not in the proper comment date order, and Engineering has been advised.
This question is still open today, perhaps it was overlooked or just lost in the volumes. Please return to this question to update it with comments if more information is needed to get your solution. If you've been helped by the participating expert(s), you may just convert their comment to the accepted answer and then grade and close. If an answer has ever been proposed you may not have this option to accept the comment as answer, if that is the case, ask the specific expert you wish to award to post an answer. This benefits others who then search our PAQ for just this solution, and rewards the experts who have provided information. A win/win scenario. Please DO NOT accept this comment as an answer, it is merely a reminder.
If you wish to award multiple participants, you can do so by creating a zero point question in the Community Support topic area, include this link and tell them which experts you'd like to award what amounts. If you'd like to delete this question, use the same process as above, but explain why you think it should be deleted. Here is the Community Support link: https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
You can always click on your profile to see all your open questions, in the event you also have other open items to be resolved. If your number of Questions Asked is not equal to the number of Answers Graded, choose to VIEW question history, and you'll quickly be able to navigate to your open items to close them as well.
I've had excellent help from experts-exchange through the years and find the real key to getting what I need is to remain active in all my questions, responding with results to suggestions until my solution is found, and recommend that highly.
Thank you very much for your responsiveness, it is very much appreciated.
":0) Asta
P.S. Some of the older questions from last year are not in the proper comment date order, and Engineering has been advised.
SECOND REQUEST.
hi
i will be asking community support to close this question in 7 days.
i will be requesting that Workshop_Alex & TOndrej recieves the points.
Regards Barry
DO NOT ACCEPT THIS COMMENT AS ANSWER
hi
i will be asking community support to close this question in 7 days.
i will be requesting that Workshop_Alex & TOndrej recieves the points.
Regards Barry
DO NOT ACCEPT THIS COMMENT AS ANSWER
Per recommendation comment force/accepted by
Netminder
Community Support Moderator
Experts Exchange
Workshop_Alex: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20277953
Netminder
Community Support Moderator
Experts Exchange
Workshop_Alex: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20277953