[Lazarus] Get JPEG from TAChart in CGI app

Leonardo M. Ramé l.rame at griensu.com
Sun Mar 20 18:22:17 CET 2011


Hi, I would like to know how can I let a CGI app return a JPeg image
from a TChart.

Here's what I'm doing:

procedure TFPWebModule1.getchartRequest(Sender: TObject; ARequest:
TRequest;
  AResponse: TResponse; var Handled: Boolean);
var
  lRect: TRect;
  lChart: TChart;
  lJPegImage: TFPMemoryImage;
  lJPegWriter: TFPWriterJPEG;
  lCanvas: TFPCustomCanvas;
begin
  lChart := TChart.Create(nil);
  lJPegImage := TFPMemoryImage.Create(100, 100);
  lJPegImage.UsePalette := False;
  lCanvas := TFPImageCanvas.create(lJPegImage);
  lJPegWriter := TFPWriterJPEG.Create;
  try
    lChart.Width := 100;
    lChart.Height := 100;
    DoSomeStuffWithTheChart(lChart);
    lRect := Rect(0,0, lChart.Width, lChart.Height);
    lCanvas.CopyRect(0,0,TFPCustomCanvas(lChart.Canvas),lRect);
    lJPegWriter.ImageWrite(AResponse.ContentStream, lJPegImage);
  finally
    lChart.Free;
    lJPegWriter.Free;
    lCanvas.Free;
    lJPegImage.Free;
  end;
  Handled := True;
end;      

After executing the method I'm getting "Control '' has no parent
window' at the CopyRect line. I'm sure there is another method to copy a
TCanvas to a TFPCustomCanvas.

Any hint?

Thanks in advance,
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com




More information about the Lazarus mailing list