Board index » cppbuilder » GIF files in resource

GIF files in resource


2004-04-02 07:39:29 AM
cppbuilder95
I have a set of GIF files that I want to include in an RC resource file.
I was following the information on:
www.bcbdev.com/faqs/faq52.htm
however, if I try to use something like:
ID_SPLASH BITMAP "splash.gif"
I get an "Invalid bitmap format".
Is there a way to include a GIF file in my resource file?
All I want to do is take the image in the resource and
create a disk file. The image is not manipulated at all.
TIA
 
 

Re:GIF files in resource

Is CBuilder support GIF?
use GIF you need licenced.
you could use TImageList save multi-frame of your Bitmaps.
"cppgraph" < XXXX@XXXXX.COM >
Quote
I have a set of GIF files that I want to include in an RC resource file.
I was following the information on:
www.bcbdev.com/faqs/faq52.htm

however, if I try to use something like:
ID_SPLASH BITMAP "splash.gif"
I get an "Invalid bitmap format".

Is there a way to include a GIF file in my resource file?
All I want to do is take the image in the resource and
create a disk file. The image is not manipulated at all.

TIA



 

Re:GIF files in resource

On Thu, 01 Apr 2004 15:39:29 -0800, cppgraph < XXXX@XXXXX.COM >wrote:
Quote
I have a set of GIF files that I want to include in an RC resource file.
I was following the information on:
www.bcbdev.com/faqs/faq52.htm

however, if I try to use something like:
ID_SPLASH BITMAP "splash.gif"
I get an "Invalid bitmap format".

Is there a way to include a GIF file in my resource file?
All I want to do is take the image in the resource and
create a disk file. The image is not manipulated at all.

TIA


You can add a .rc file to your project. For example, you can create
a file Images.rc which has a line like the following:
THE_GIF RCDATA "your_image.gif"
Then, in order to gain the access to the resource, you can use a snippet
(untested) like this:
{
....
....
// Search for the resource
HRSRC const ResourceHandle = FindResource( 0, "THE_GIF", RT_RCDATA );
if ( !ResourceHandle )
RaiseLastOSError();
// Get the memory for the loaded resource
HGLOBAL const MemBlock = LoadResource( 0, ResourceHandle );
if ( !MemBlock )
RaiseLastOSError();
// Obtain the size for the resource
DWORD const Size = SizeofResource( 0, ResourceHandle );
if ( !Size )
RaiseLastOSError();
// Get the memory location of the loaded resource
LPVOID const Data = LockResource( MemBlock );
if ( !Data )
throw Exception( "LockResource failed" );
// Create a stream for the loaded resource
auto_ptr<TMemoryStream>const MemStream( new TMemoryStream );
MemStream->SetSize( int( Size ) );
CopyMemory( MemStream->Memory, Data, Size );
// Now, you can use LoadFromStream (if exists) for the GIF component
// you have chosen.
// For example, if you are using the TGIFImage component from
// Anders Melander ( delphi.icm.edu.pl/ftp/d20free/gifimage.exe )
// you can assign the content of the stream in this manner:
auto_ptr<TGIFImage>const GIFImage( new TGIFImage );
GIFImage->LoadFromStream( MemStream.get() );
....
....
// Draw!!!
YourDestinationCanvas->Draw( 0, 0, GIFImage.get() );
}
HTH
Giuliano
 

{smallsort}

Re:GIF files in resource

Giuliano,
Thank you so much for your assistance. Though I'm not well versed
with the Microsoft API, I was able to muddle through and determine
the parts that I needed.
To those interested, I have added details to Giuliano's code that
I required for my situation.
As a side note... You know, I sometimes wonder whether I could
work as a one-man shop without the help of the people like
Giuliano. It's a great resource (no pun intended).
Giuliano wrote:
Quote
On Thu, 01 Apr 2004 15:39:29 -0800, cppgraph < XXXX@XXXXX.COM >wrote:

>I have a set of GIF files that I want to include in an RC resource file.
>I was following the information on:
>www.bcbdev.com/faqs/faq52.htm
>
>however, if I try to use something like:
>ID_SPLASH BITMAP "splash.gif"
>I get an "Invalid bitmap format".
>
>Is there a way to include a GIF file in my resource file?
>All I want to do is take the image in the resource and
>create a disk file. The image is not manipulated at all.
>
>TIA
>
>

You can add a .rc file to your project. For example, you can create
a file Images.rc which has a line like the following:

THE_GIF RCDATA "your_image.gif"
The ".rh" include file is not required as documented in
www.bcbdev.com/faqs/faq52.htm
since this does not use LoadFromResourceID()
Quote
Then, in order to gain the access to the resource, you can use a snippet
(untested) like this:

{
....
....

// Search for the resource
HRSRC const ResourceHandle = FindResource( 0, "THE_GIF", RT_RCDATA );
if ( !ResourceHandle )
RaiseLastOSError();

// Get the memory for the loaded resource
HGLOBAL const MemBlock = LoadResource( 0, ResourceHandle );
if ( !MemBlock )
RaiseLastOSError();

// Obtain the size for the resource
DWORD const Size = SizeofResource( 0, ResourceHandle );
if ( !Size )
RaiseLastOSError();

// Get the memory location of the loaded resource
LPVOID const Data = LockResource( MemBlock );
if ( !Data )
throw Exception( "LockResource failed" );
Because I just needed to create a disk file of the ".GIF" file stored in the
resource, the following was replaced (see below). (plus the fact that
I was getting errors with auto_ptr and I don't know how to use it).
Quote
// Create a stream for the loaded resource
auto_ptr<TMemoryStream>const MemStream( new TMemoryStream );
MemStream->SetSize( int( Size ) );
CopyMemory( MemStream->Memory, Data, Size );

// Now, you can use LoadFromStream (if exists) for the GIF component
// you have chosen.
// For example, if you are using the TGIFImage component from
// Anders Melander ( delphi.icm.edu.pl/ftp/d20free/gifimage.exe )
// you can assign the content of the stream in this manner:
auto_ptr<TGIFImage>const GIFImage( new TGIFImage );
GIFImage->LoadFromStream( MemStream.get() );

....
....

// Draw!!!
YourDestinationCanvas->Draw( 0, 0, GIFImage.get() );
// write the data in memory to a disk file.
destFilename= "xyz.gif";
FILE * outFile= fopen(destFilename.c_str(),"wb");
int i= fwrite(Data,1,Size,outFile);
if (i==0)
throw Exception("fwrite() error");
fclose(outFile);
 

Re:GIF files in resource

Quote
// Obtain the size for the resource
DWORD const Size = SizeofResource( 0, ResourceHandle );
if ( !Size )
RaiseLastOSError();

The SizeofResource function returns the size, in bytes, of the specified
resource.
DWORD SizeofResource(
HMODULE hModule, // resource-module handle
HRSRC hResInfo // resource handle
);
Return Values
If the function succeeds, the return value is the number of bytes in the
resource.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
Remarks
The value returned may be larger than the actual resource because of
alignment.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
An application should not rely upon this value for the exact size of a
resource.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quote
// Create a stream for the loaded resource
auto_ptr<TMemoryStream>const MemStream( new TMemoryStream );
MemStream->SetSize( int( Size ) );
CopyMemory( MemStream->Memory, Data, Size );

 

Re:GIF files in resource

On Sat, 3 Apr 2004 04:59:26 +0800, "Cactus" < XXXX@XXXXX.COM >wrote:
Quote
The value returned may be larger than the actual resource because of
alignment.
 

Re:GIF files in resource

Quote
I was getting errors with auto_ptr and I don't know how to use it).


>// Create a stream for the loaded resource
>auto_ptr<TMemoryStream>const MemStream( new TMemoryStream );
>MemStream->SetSize( int( Size ) );
>CopyMemory( MemStream->Memory, Data, Size );
I use TMemoryStream *MemStream = new TMemoryStream;
and the "auto_ptr<>" just a template wrap the operate same for above.
MemStream->WriteBuffer() also load data from memory to Stream.
Giuliano is given a good example for load user define data from resource.
;-)