view image in .res file

Hi, I've got some .res files that I'd like to read / view with delphi, but I don't know how. Each .res file contains a number of bitmaps.

So far, I have something like:

var
  MyImageList : TImageList;
  restype: TResType;
  result : boolean;
begin
restype := rtBitmap;
MyImageList := TImageList.CreateSize( 1000,1000 );
result := MyImageList.ResourceLoad(restype, 'Horship1.res', $00FF0000);
if result then Label1.Caption := 'ok' else label1.caption := 'not ok';
Image1.Picture.Assign(MyImageList);
MyImageList.Free;
end;

But it doesn't seem to work. Can anyone help?
MaestroDaveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
HI
try this to se if helps:
Regards Barry


type
  ELoadImages = class(Exception)
      end;
 
procedure LoadBitMapResource(Images : TImageList; const AName : string; BackgroundColor : TColor);
begin
  if not Images.GetResource(rtBitmap, UpperCase(AName),Images.Width, [lrDefaultColor,lrDefaultSize, lrTransparent], BackgroundColor) then
 raise ELoadImages.Create('Unable to load '+AName+' bitmap !');
 end;

0
MaestroDaveAuthor Commented:
hmmm - that didn't work. I'm not saying your code is bad though - maybe there's some reason I cannot open the file. I got the exception 'Unable to load...'.

I know nothing about .res files.  All I know is that I can open it using MS C++ builder.
0
rwilson032697Commented:
Don't the resources have to be compiled into the exe for this to work?

ie: add

{$R horship1.res}

to the .DPR file.

And call your code/barry's code with the name of a resource in the res file (you can see the names in C++ builder...)

Cheers,

Raymond.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

MaestroDaveAuthor Commented:
OK, did that. Now get a compilation error:
[Error] RLINK32: Unsupported 16bit resource in file "C:\Steph\horship1.res"
0
rwilson032697Commented:
That would explain a lot!

The easiest thing is probably to create a new 32 bit resource file in VC++ and copy the resources from the 16 bit res file to the 32 bit one (either that or locate the original .RC file and images and recompile the res file)

Once you have done that give it another
go...

Cheers,

Raymond.
0
MaestroDaveAuthor Commented:
Ok, I can now load it, but still don't know how to display it on a form...?
0
rwilson032697Commented:
Try this:

var
  Bmp : TBitmap;

....

  Bmp := TBitmap.Create;
  Bmp.LoadFromResourceName(HInstance, 'Fred'); // Fred is resource name
  APicture.bitmap.assign(bmp); // APicture is a TPicture on a form
....

Cheers,

Raymond.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MaestroDaveAuthor Commented:
Cheers Barry & Raymond.  I should really be giving you both points, cause you both helped heaps.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.