Recent

Author Topic: How to save complete Stringgrid to bmp file?  (Read 2714 times)

barsoom

  • New Member
  • *
  • Posts: 49
How to save complete Stringgrid to bmp file?
« on: August 03, 2021, 11:33:34 pm »
I have a stringgrid that i want to save as an image.

After searching in this forum, and googling i found different "solutions" but any of them solve my problem, because all of them, result on saving the visible part of the stringgrid. However, my stringgrid is wider and longer than the client  width and height of its ccanvas.

Here is the simpler code i found that results on saving the visible part:
https://forum.lazarus.freepascal.org/index.php/topic,34206.msg223660.html#msg223660
and this is the code they used:
Quote
var
bmpp: TBitmap;
begin
bmpp:= TBitmap.Create;
  try
    bmpp.LoadFromDevice(StringGrid1.Canvas.Handle); // is a HDC
    bmpp.SaveToFile('vv.bmp');
  finally
    bmpp.Free;
  end;
end;

Any idea about how could i have an image of the whole stringgrid?

Thanks in advance.

jamie

  • Hero Member
  • *****
  • Posts: 4845
Re: How to save complete Stringgrid to bmp file?
« Reply #1 on: August 04, 2021, 12:18:42 am »
It is not that simple.

 First, implement owner draw mode of the string grid. Do all of the drawing of the cells in your code and when you have that perfected then you use the same code in the draw method to repeat the process except you draw to the surface of a bitmap instead.

 Create a double for loop X,Y so you can scan the complete cell count and for each cell you execute the same code you did for the owner draw except draw on an image instead.

 At least this way you can get all of the cells , not just those that are visible.
The only true wisdom is knowing you know nothing

barsoom

  • New Member
  • *
  • Posts: 49
Re: How to save complete Stringgrid to bmp file?
« Reply #2 on: August 09, 2021, 07:40:00 pm »
Thanks so much @jamie for your reply.

Ok, i see it is not as simple as i assumed... it i a pity.
Okay, i will explore the procedure you explained. Thanks.

 

TinyPortal © 2005-2018