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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rwilson032697Connect With a Mentor Commented:
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
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
 
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
 
MaestroDaveAuthor Commented:
Cheers Barry & Raymond.  I should really be giving you both points, cause you both helped heaps.
0
All Courses

From novice to tech pro — start learning today.