Link to home
Start Free TrialLog in
Avatar of kaloyan
kaloyan

asked on

How to load a JPEG image from resource file?

How to load a JPEG image from resource file?
Avatar of Thaddy
Thaddy

Is the resource a custom resource? i.e JPEG internal,
or is the resource just a standard BMP?
Avatar of kaloyan

ASKER

It's a custom resource(I import it with J++).
This is from Borland groups. Hope this helps:


"...Michael Harings wrote in message <01bcdfd3$79145380$803919d0@dell100>...
                  >I'm making a screen saver, but don't want users to take the images. So I'm
                  >wondering how to store the jpg files so user's can't access them. Any ideas
                  >welcome. I originally thought I could store them in an image file like a
                  >bitmap, but after getting ImgLib found out otherwise. TIA!
                  >
                  Make a resource file like so:

                  <---- Cut ---->

                  SPLASHBACKGROUND JPEG "..\Images\Splash\Splash.jpg"

                  <---- Cut ---->

                  Save that as images.rc (or whatever)

                  Run brcc32 images.rc (in your Program Files\Borland\Delphi 3\Bin folder)

                  This will make images.res

                  Add the resource to a DLL or your main project like so:

                  {$R Images.Res}


                  Then use this function... If you are not using a DLL just pass in
                  Application.Handle
                  Pass in SPLASHBACKGROUND and then pass in Image1.Picture.

                  Procedure LoadJPEGFromRes(TheDLLHandle : LongInt; TheJPEG : String;
                  ThePicture : TPicture);
                  Var TmpResHandle : THandle;
                      TmpMemHandle : THandle;
                      TmpMemStream : TMemoryStream;
                      TmpResPtr : PByte;
                      TmpResSize : Longint;
                      TmpJPEGImage : TJPEGImage;
                  Begin
                   TmpResHandle := FindResource(TheDLLHandle, PChar(TheJPEG), 'JPEG');
                   TmpMemHandle := LoadResource(TheDLLHandle, TmpResHandle);
                   TmpResPtr := LockResource(TmpMemHandle);
                   TmpMemStream := TMemoryStream.Create;
                   TmpJPEGImage := TJPEGImage.Create;
                    Try
                     TmpResSize := SizeOfResource(TheDLLHandle, TmpResHandle);
                      TmpMemStream.SetSize(TmpResSize);
                      TmpMemStream.Write(TmpResPtr^, TmpResSize);
                      FreeResource(TmpMemHandle);
                      TmpMemStream.Seek(0, 0);
                      TmpJPEGImage.LoadFromStream(TmpMemStream);
                      ThePicture.Assign(TmpJPEGImage);
                    Finally
                     TmpJPEGImage.Free;
                     TmpMemStream.Free;
                    End;
                  End;


                   - Jeff..."
ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaloyan

ASKER

Thanks!
No problem :-)

Niama problemi :-)

Regards,
Viktor Ivanov