I store PNG image into Ini file with the following code :
procedure TfrmParametres.SaveIni;
var
IniFile: TIniFile;
MS: TMemoryStream;
PNG: TPngImage;
begin
IniFile := TIniFile.Create(IniFileName);
try
PNG := TPngImage.Create;
try
PNG.LoadFromFile(edtLogo.Text);//edtlogo contain image file path
MS := TMemoryStream.Create;
try
PNG.SaveToStream(MS);
MS.Seek(0, 0);
IniFile.WriteBinaryStream('REPORT_HEADER', 'LOGO', MS);
finally
MS.Free;
end;
finally
PNG.Free;
end;
finally
FreeAndNil(IniFile);
end;
end;
and to show the picture in another form OnShow event I used the same approach :
Load DATA in TMemoryStream object
Load DATA from MemoryStream into TPngImage object
Show the picture in TImage component
procedure TfrmLoadPicture.FormShow(Sender: TObject); var IniFile: TIniFile; MS: TMemoryStream; PNG: TPngImage; begin IniFile:= TIniFile.Create(frmParametres.IniFileName); try MS:= TMemoryStream.Create; try IniFile.ReadBinaryStream('REPORT_HEADER', 'LOGO', MS); PNG := TPngImage.Create; try MS.Seek(0, 0); PNG.LoadFromStream(MS); Image.Picture.Assign(PNG); finally PNG.Free; end; finally MS.Free; end; finally IniFile.Free; end; end;
however I always get Exception error:
