Recent

Author Topic: [SOLVED]How to save multiple controls into one image file?  (Read 2967 times)

CM630

  • Hero Member
  • *****
  • Posts: 910
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
I need to save several TAcharts into one image file. They shall be placed one to another as they are placed in  the frame (sometimes their total height might be greater than the height of the screen). I hope there is an easy solution?
Merging (adding) several images into one might b okay for me, since all the TACharts are one under another and they have equal dimensions.
Separate TACharts are exported easily- Chart.SaveToBitmap(..)

EDIT: So far I did things with ImageMagick: convert -append SourceImage1.bmp SourceImage2.bmp SourceImage3.bmp ..... TargetImage.bmp but I'd prefer a more native way?
« Last Edit: May 17, 2013, 01:06:19 pm by paskal »
Лазар 2,0,8; W10 or W7 64bit; FPC3,2,0; rev 62944

wp

  • Hero Member
  • *****
  • Posts: 7551
Re: How to save multiple controls into one image file?
« Reply #1 on: May 14, 2013, 09:26:43 am »
  • Find the total height and maximum width of your charts.
  • Create a bitmap and set its size accordingly.
  • For each chart: create a temporary bitmap by calling SaveToImage(TBitmap), draw it onto the canvas of the total bitmap in the correct vertical position, free the temporary bitmap.
  • Save the total bitmap to file, use standard bitmap techniques for file format conversion.

This works for two charts:
Code: [Select]
procedure TForm1.SaveTwoCharts(AFileName: String);
var
  w,h: Integer;
  y : Integer;
  bmp: TBitmap;
  img: TRasterImage;
begin
  w := max(Chart1.Width, Chart2.Width);
  h := Chart1.Height + Chart2.Height;

  bmp := TBitmap.Create;
  try
    bmp.SetSize(w, h);
    y := 0;
    img := Chart1.SaveToImage(TBitmap);
    try
      bmp.Canvas.Draw(0, y, img);
      y := y + Chart1.Height;
    finally
      img.Free;
    end;
    img := Chart2.SaveToImage(TBitmap);
    try
      bmp.Canvas.Draw(0, y, img);
    finally
      img.Free;
    end;
    bmp.SaveToFile(AFileName);
  finally
    bmp.Free;
  end;
end;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

CM630

  • Hero Member
  • *****
  • Posts: 910
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: [SOLVED]How to save multiple controls into one image file?
« Reply #2 on: May 17, 2013, 01:06:48 pm »
Thanks, it's perfect!
Лазар 2,0,8; W10 or W7 64bit; FPC3,2,0; rev 62944

 

TinyPortal © 2005-2018