Search code examples
imagedelphifiremonkey

Add date in taken picture DELPHI FIREMONKEY


For a photo app that I am making, the date on which the photo was taken must be in the photo. and then saved in the folder. Now I don't know what components to use to do this. or how to do this at all.

Like this :

Thanks in advance for any help !!


Solution

  • You don't need any component to do so, just use the TCanvas of the TBitmap as:

    Var
      R: TRectF;
      Img: TBitmap;
    begin
      Img:= TBitmap.Create;
      try
        Img.LoadFromFile('C:\MyPic.jpg');
        R.Create(Img.Width - 100, Img.Height - 100, Img.Width, Img.Height);
        Img.Canvas.BeginScene();
        Img.Canvas.Fill.Kind:= TBrushKind.Solid;
        Img.Canvas.Stroke.Thickness:= 12;
        Img.Canvas.Stroke.Color:= TAlphaColors.White;
        Img.Canvas.FillText(
        R, DateToStr(Now), False, 100, [TFillTextFlag.RightToLeft], TTextAlign.Center);
        Img.Canvas.EndScene;
        Img.SaveToFile('D:\Result.jpg');
      finally
        Img.Free;
      end;
    

    If you want to set the creation date to the picture, you can use TFile.SetCreationTime().