Reputation: 474
I am trying to read some gif and bitmaps from resource file, I am using resource hacker to include the images into project.res file but the code I am using doesn't seem to return the right count of images.
Below is what I am trying to do
Stream := TResourceStream.Create(HInstance,'EMOTES','BIN');
GetMem(Buffer,40000);
Stream.Read(StreamCount,4);
For I := 0 To StreamCount - 1 Do Begin
Stream.Read(StreamSize,4);
Stream.Read(Buffer^,StreamSize);
ImageStream := TMemoryStream.Create;
ImageStream.Write(Buffer^,StreamSize);
ImageStreamList.Add(ImageStream);
ImageStream.Free;
End;
FreeMem(Buffer);
Stream.Free;
Upvotes: 0
Views: 3003
Reputation: 612794
You appear to be trying to load a GIF file from a resource. Do it like this:
Stream := TResourceStream.Create(HInstance, 'EMOTES', 'BIN');
try
image.LoadFromStream(Stream);
finally
Stream.Free;
end;
where image
is an instantiated object of type TGIFImage
.
I really cannot work out what your code is trying to do. Perhaps you have multiple images. In which case create one resource for each image, each resource having a different name. Note that I don't mean one .res file per image. You can put all your images into a single .rc file, each resource with a different name. Then compile that .rc file to a .res file and link to your application.
Upvotes: 3