Anna Kirova
asked on
How to insert .png images to TClientDataSet .cds file?
I'm using Delphi XE8. Multi-device application.
Im my .cds file I've Field :[ID] Field type:ftAutoInc and Field :[IMAGE] Field type:ftGraphic.
I'd like insert only .png image to .cds file. But when I insert .png image into .cds it's inserting. when I try to load from .cds it gives message "Bitmap image is not valid".
So how to Solve this problem?
Thanks in Advance!
Here is my code:
Im my .cds file I've Field :[ID] Field type:ftAutoInc and Field :[IMAGE] Field type:ftGraphic.
I'd like insert only .png image to .cds file. But when I insert .png image into .cds it's inserting. when I try to load from .cds it gives message "Bitmap image is not valid".
So how to Solve this problem?
Thanks in Advance!
Here is my code:
procedure TForm1.btnImageInsertClick(Sender: TObject);
var
LStream : TMemoryStream;
begin
if OpenDialog1.Execute then
begin
Image1.Bitmap.LoadFromFile(OpenDialog1.FileName);
LStream := TMemoryStream.Create;
Image1.Bitmap.SaveToStream(LStream);
{
cdsMenu2.Insert;
cdsMenu2.FieldByName('IMAGE').Assign(Image1.Bitmap);
cdsMenu2.Post;
}
cdsMenu2.Insert;
TBlobField(cdsMenu2.FieldByName('IMAGE')).LoadFromStream(LStream);
cdsMenu2.Post;
cdsMenu2.SaveToFile(ExtractFileDir(ParamStr(0))+'\db\menu2.cds');
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
try
finally
LStream.Free;