uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtCtrls,
Vcl.StdCtrls, JPEG, PNGImage, GIFImg;
...
function GetGraphicFromResource(
Name:
String): TGraphic;
var
RS: TResourceStream;
ImageBMP : TBitmap;
ImageJPG : TJPEGImage;
ImagePNG : TPNGImage;
ImageGif : TGIFImage;
FileExtension :
String;
Graphic : TGraphic;
begin
FileExtension := LowerCase(Copy(
Name, Length(
Name)-2, 3));
Graphic := TGraphic.Create;
Graphic :=
nil;
RS := TResourceStream.Create(hInstance,
Name, RT_RCDATA);
try
if FileExtension = LowerCase('
bmp')
then
begin
ImageBMP := TBitmap.Create;
try
ImageBMP.LoadFromStream(RS);
Graphic := ImageBMP;
finally
ImageBMP.Free;
end;
end;
if FileExtension = LowerCase('
jpg')
then
begin
ImageJPG := TJPEGImage.Create;
try
ImageJPG.LoadFromStream(RS);
Graphic := ImageJPG;
finally
ImageJPG.Free;
end;
end;
if FileExtension = LowerCase('
jpeg')
then
begin
ImageJPG := TJPEGImage.Create;
try
ImageJPG.LoadFromStream(RS);
Graphic := ImageJPG;
finally
ImageJPG.Free;
end;
end;
if FileExtension = LowerCase('
png')
then
begin
ImagePNG := TPNGImage.Create;
try
ImagePNG.LoadFromStream(RS);
Graphic := ImagePNG;
finally
ImagePNG.Free;
end;
end;
if FileExtension = LowerCase('
gif')
then
begin
ImageGif := TGIFImage.Create;
try
ImageGif.LoadFromStream(RS);
Graphic := ImageGif;
finally
ImageGif.Free;
end;
end;
finally
RS.Free;
end;
if Graphic <>
nil then
begin
showmessage('
gr vorhanden');
//Form1.image1.Picture.Graphic := graphic;
//showmessage('gr vorhanden');
Result := Graphic;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
image1.Picture.Graphic :=
nil;
image1.Picture.Graphic := (GetGraphicFromResource('
bild_jpg'));
//image1.Picture.Graphic.Assign(GetGraphicFromResource('bild_jpg'));
end;