kaloyan
asked on
How to load a JPEG image from resource file?
How to load a JPEG image from resource file?
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$803919d 0@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.j pg"
<---- 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(TheDLLHand le : 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(TheDLLHandl e, TmpResHandle);
TmpMemStream.SetSize(TmpRe sSize);
TmpMemStream.Write(TmpResP tr^, TmpResSize);
FreeResource(TmpMemHandle) ;
TmpMemStream.Seek(0, 0);
TmpJPEGImage.LoadFromStrea m(TmpMemSt ream);
ThePicture.Assign(TmpJPEGI mage);
Finally
TmpJPEGImage.Free;
TmpMemStream.Free;
End;
End;
- Jeff..."
"...Michael Harings wrote in message <01bcdfd3$79145380$803919d
>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.j
<---- 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(TheDLLHand
ThePicture : TPicture);
Var TmpResHandle : THandle;
TmpMemHandle : THandle;
TmpMemStream : TMemoryStream;
TmpResPtr : PByte;
TmpResSize : Longint;
TmpJPEGImage : TJPEGImage;
Begin
TmpResHandle := FindResource(TheDLLHandle,
TmpMemHandle := LoadResource(TheDLLHandle,
TmpResPtr := LockResource(TmpMemHandle)
TmpMemStream := TMemoryStream.Create;
TmpJPEGImage := TJPEGImage.Create;
Try
TmpResSize := SizeOfResource(TheDLLHandl
TmpMemStream.SetSize(TmpRe
TmpMemStream.Write(TmpResP
FreeResource(TmpMemHandle)
TmpMemStream.Seek(0, 0);
TmpJPEGImage.LoadFromStrea
ThePicture.Assign(TmpJPEGI
Finally
TmpJPEGImage.Free;
TmpMemStream.Free;
End;
End;
- Jeff..."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
No problem :-)
Niama problemi :-)
Regards,
Viktor Ivanov
Niama problemi :-)
Regards,
Viktor Ivanov
or is the resource just a standard BMP?