summaryrefslogtreecommitdiff
path: root/src/corelib
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2012-08-31 18:58:29 +0100
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2012-08-31 18:58:29 +0100
commit3aa5c183bc80bb2132ac06d0877eb70ee4505d8b (patch)
tree471ac5eff43f6884675ebe152c8b0c59c76849e9 /src/corelib
parent4602a4ee9c0ed69cdeb39895e7b190e711dcb163 (diff)
downloadfpGUI-3aa5c183bc80bb2132ac06d0877eb70ee4505d8b.tar.xz
Implements loading PNG images from a Stream or Resource.
Thanks to Dibo for this contribution.
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/fpg_imgfmt_png.pas43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/corelib/fpg_imgfmt_png.pas b/src/corelib/fpg_imgfmt_png.pas
index 19f6b8cc..d0620672 100644
--- a/src/corelib/fpg_imgfmt_png.pas
+++ b/src/corelib/fpg_imgfmt_png.pas
@@ -29,7 +29,9 @@ uses
FPImage,
FPReadPNG;
-function LoadImage_PNG(const AFileName: TfpgString): TfpgImage;
+function LoadImage_PNG(const AFileName: TfpgString): TfpgImage; overload;
+function LoadImage_PNG(AStream: TStream): TfpgImage; overload;
+function LoadImage_PNG(AInstance: THandle; const AResName: String; AResType: PChar): TfpgImage; overload;
function LoadImage_PNGcrop(const AMaxWidth, AMaxHeight: integer; const AFileName: TfpgString): TfpgImage;
@@ -83,6 +85,45 @@ begin
end;
end;
+function LoadImage_PNG(AStream: TStream): TfpgImage;
+var
+ imga: TFPMemoryImage;
+begin
+ Result := nil;
+ if AStream = nil then
+ Exit;
+
+ imga := TFPMemoryImage.Create(0, 0);
+ try
+ try
+ AStream.Position := 0;
+ imga.LoadFromStream(AStream, TFPReaderPNG.Create); // auto size image
+ Result := FPImageToFPG(imga);
+ except
+ on e: Exception do
+ begin
+ Result := nil;
+ raise; // so we can report PNG errors (eg: missing resource name)
+ end;
+ end;
+ finally
+ imga.Free;
+ end;
+end;
+
+function LoadImage_PNG(AInstance: THandle; const AResName: String; AResType: PChar): TfpgImage;
+var
+ res: TResourceStream;
+begin
+ try
+ res := TResourceStream.Create(AInstance, AResName, AResType);
+ Result := LoadImage_PNG(res);
+ finally
+ if res <> nil then
+ res.Free;
+ end;
+end;
+
function LoadImage_PNGcrop(const AMaxWidth, AMaxHeight: integer; const AFileName: TfpgString): TfpgImage;
var
i, j: integer;