Re:JPEG -> BMP conversion in Delphi
Quote
In article <01bbb214.c2f7a440$0565a8c0@rafe> r...@oxfordcc.co.uk writes:
>> Also, is there any way I can store a JPEG in a resource file and load it
>at >> run-time? This is the one shortcoming I have with JPEGs, and that's
>that I am
>> going to have to ship around 1400 jpeg files unless I can get them into
>> resource files!
>You could use TCompress to store all the jpegs into a single file,
>extracting them as needed. Find out more by visiting www.spis.co.nz.
Well, no, TCompress would not be ideal for handling JPEGs, because they are
already highly compressed. You could conveniently use it if you had
*already* expanded each image to a bitmap and wanted to store the latter
compressed in a resource file.
However, some clues for you:
a) TCompress 2.5 has some sample projects showing how to get binary
resources into a resource file -- i.e. the general approach would be of
interest to get you going
b) The code below is a general routine to get a stream handle to a resource
from a program (or DLL) using Delphi 2.0's convenient TResourceStream -- in
Delphi 1 it is a *little* harder, but not heaps.
function LoadMyResource(ResourceName, DLLName: string): TStream;
var hFileInstance : THandle;
begin
result := nil;
if DLLName<>'' then
begin
hFileInstance := LoadLibrary(PChar(DLLName)); { Load DLL }
if hFileInstance=NULL then { oops }
raise(Exception.create('Could not load '+DLLName+' DLL'));
end else
hFileInstance := HInstance; { the handle to the current EXE }
try
result :=
TResourceStream.Create(hFileInstance,ResourceName,PChar('YOUR_RESOURCE_TYPE'));
finally
if DLLName<>'' then { must free Library }
FreeLibrary(hFileInstance ); { Always Unload DLL }
end;
end;
Hope this helps.
cheers,
peter
--
====================================================================
Peter Hyde, South Pacific Information Services Ltd, Christchurch, NZ
* SPIS Webview 2.5 Offline Browser and WebWatch 1.01 Site Monitor
* "Climbing Out on the Web" web site primer
* TCompress 2.5 File and Database Compression for Delphi
Find all the above and MORE at http://www.spis.co.nz/