For some reason I cannot find useful resources to pinpoint out how to do this.
Picture : TPicture;
Bitmap: TBitmap;
---------------------------
Picture := TPicture.Create;
try
Picture.LoadFromFile('path\to\file\file.jpg');
Bitmap := TBitmap.Create;
try
Bitmap.Width := Picture.Width;
Bitmap.Height := Picture.Height;
Bitmap.Canvas.Draw(0, 0, Picture.Graphic);
with dtm.cds do //Data module and client data set
begin
//TODO
end;
finally
Bitmap.Free;
end;
finally
Picture.Free;
end;
Now I have a bitmap, next I have created a Stream:TStream
object and a blobfield :TBlobField
Object as well but not sure how to connect the chain
Pardon my ignorance when it comes to this, I am new to delphi and not really sure how approach this issue.
Thanks in advance.
EDIT**** Now this is what I have, but still not getting an image
Picture := TPicture.Create;
try
Picture.LoadFromFile('path\to\file\file.jpg');
Bitmap := TBitmap.Create;
try
Bitmap.Width := Picture.Width;
Bitmap.Height := Picture.Height;
Bitmap.Canvas.Draw(0, 0, Picture.Graphic);
with dtm.cds do //Data module and client data set
begin
edit ;
myStream := dtm.cdsr.CreateBlobStream(dtm.cds.FieldByName('PICTURE'),bmWrite);
Bitmap.SaveToStream(myStream);
post;
ApplyUpdates(-1);
end;
finally
Bitmap.Free;
end;
finally
Picture.Free;
end;
This is how I am displaying iamges, which is working fine for the ones currently in the database
jpg.Free;
stream.Free;
img.Free;
Stream := dtm.cds.CreateBlobStream(dtm.cds.FieldByName('PICTURE'), bmRead);
JPG := TJPEGImage.Create;
jpg.LoadFromStream(Stream);
//The position of the image on the form.
Img := TImage.Create(Self);
Img.Parent := Self;
Img.Left := 160;
Img.Top := 4;
Img.AutoSize := True;
Img.Stretch := True;
img.Picture.Assign(jpg);