Geht beides, der Fehler muß außerhalb liegen.
Ich würde die Basisklasse TStream übergeben....
Delphi-Quellcode:
function SetPngPic(Image : TImage; TheStream : TStream) : boolean;
var
_PNGImage : TPNGImage;
Stream : TMemoryStream;
begin
try
Result := true;
Stream := TMemoryStream.Create;
_PNGImage := TPNGImage.Create;
try
Stream.LoadFromStream(TheStream);
_PNGImage.LoadFromStream(Stream);
Image.Picture.Assign(_PNGImage);
except
Result := false;
end;
finally
_PNGImage.Free;
Stream.Free;
end;
end;
function SetPngPic2(Image : TImage; TheStream : TStream) : boolean;
var
_PNGImage : TPNGImage;
begin
try
Result := true;
_PNGImage := TPNGImage.Create;
try
_PNGImage.LoadFromStream(TheStream);
Image.Picture.Assign(_PNGImage);
except
Result := false;
end;
finally
_PNGImage.Free;
end; end;
procedure TForm1.Button1Click(Sender: TObject);
var
s:TFileStream;
begin
s :=TFileStream.Create('C:\Bilder\h2o1.png',fmOpenRead );
try
//SetPngPic(Image1,s);
SetPngPic2(Image1,s);
finally
s.Free;
end;
end;