Lazarus
Programming => General => Topic started by: barsoom 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 (https://forum.lazarus.freepascal.org/index.php/topic,34206.msg223660.html#msg223660)
and this is the code they used:
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.
-
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.
-
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.