Board index » cppbuilder » GIF files in resource
|
cppgraph
CBuilder Developer |
|
cppgraph
CBuilder Developer |
GIF files in resource2004-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 |
| Cactus
CBuilder Developer |
2004-04-02 11:30:55 AM
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 > QuoteI have a set of GIF files that I want to include in an RC resource file. |
| gcardinali
CBuilder Developer |
2004-04-02 06:11:29 PM
Re:GIF files in resource
On Thu, 01 Apr 2004 15:39:29 -0800, cppgraph < XXXX@XXXXX.COM >wrote:
QuoteI have a set of GIF files that I want to include in an RC resource file. 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} |
| cppgraph
CBuilder Developer |
2004-04-03 03:50:52 AM
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: QuoteOn Thu, 01 Apr 2004 15:39:29 -0800, cppgraph < XXXX@XXXXX.COM >wrote: since this does not use LoadFromResourceID() QuoteThen, in order to gain the access to the resource, you can use a snippet I was getting errors with auto_ptr and I don't know how to use it). Quote// Create a stream for the loaded resource FILE * outFile= fopen(destFilename.c_str(),"wb"); int i= fwrite(Data,1,Size,outFile); if (i==0) throw Exception("fwrite() error"); fclose(outFile); |
| Cactus
CBuilder Developer |
2004-04-03 04:59:26 AM
Re:GIF files in resourceQuote// Obtain the size for the 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 |
| Giuliano
CBuilder Developer |
2004-04-03 07:11:07 AM
Re:GIF files in resource
On Sat, 3 Apr 2004 04:59:26 +0800, "Cactus" < XXXX@XXXXX.COM >wrote:
QuoteThe value returned may be larger than the actual resource because of |
| Cactus
CBuilder Developer |
2004-04-03 12:35:43 PM
Re:GIF files in resourceQuoteI was getting errors with auto_ptr and I don't know how to use it). MemStream->WriteBuffer() also load data from memory to Stream. Giuliano is given a good example for load user define data from resource. ;-) |
