Forum > Carbon
Copy stringgrid canvas in image
xinyiman:
For my project i have necessity to copy my string grid (with image and rectangol color) into image. But into Mac Os X not work return all black image. Where is the problem?
Thank you
PS: sGanttChart1 is my TStringGrid
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button3Click(Sender: TObject);var Bitmap : TBitmap; DC : HDC ;begin Bitmap := TBitmap.Create; DC := GetDC(Self.sGanttChart1.Handle); Bitmap.LoadFromDevice(DC); Bitmap.SaveToFile('/tmp/screen.png'); ReleaseDC(Self.sGanttChart1.Handle, DC) ; Bitmap.Free; ShowMessage('ok');end; procedure TForm1.Button4Click(Sender: TObject);var h: THandle; bmp: TBitmap;begin h := sGanttChart1.Handle; bmp := TBitmap.Create; bmp.Width := sGanttChart1.Width; bmp.Height := sGanttChart1.Height; Image1.Width := sGanttChart1.Width; Image1.Height := sGanttChart1.Height; BitBlt(bmp.Canvas.Handle, 0, 0, sGanttChart1.Width, sGanttChart1.Height, sGanttChart1.Canvas.handle, 0, 0, SRCCOPY); Image1.Picture.Bitmap.Assign(bmp); //Image1.Picture.Bitmap.SaveToFile('c:\sg1.bmp'); bmp.Free; end;
RayoGlauco:
This code works for me (tested on Windows):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var bmp: Graphics.TBitmap;begin bmp := Graphics.TBitmap.Create; bmp.SetSize(StringGrid1.ClientWidth, StringGrid1.ClientHeight); bmp.Canvas.Brush.Color := clWhite; bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height); StringGrid1.PaintTo(bmp.Canvas, 0, 0); bmp.SaveToFile('test.bmp'); FreeAndNil(bmp);end;
xinyiman:
--- Quote from: RayoGlauco on July 13, 2018, 01:16:35 pm ---This code works for me (tested on Windows):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var bmp: Graphics.TBitmap;begin bmp := Graphics.TBitmap.Create; bmp.SetSize(StringGrid1.ClientWidth, StringGrid1.ClientHeight); bmp.Canvas.Brush.Color := clWhite; bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height); StringGrid1.PaintTo(bmp.Canvas, 0, 0); bmp.SaveToFile('test.bmp'); FreeAndNil(bmp);end;
--- End quote ---
Thank you, but not work on Mac. Return all white image
Josh:
No tested on Mac..
Maybe?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var bmp:tbitmap;begin bmp:=TBitmap.Create; bmp.SetSize(stringgrid1.ClientWidth,stringgrid1.ClientHeight); bmp.PixelFormat:= pf24bit; bmp.Canvas.Brush.Color := clWhite; bmp.clear; StringGrid1.PaintTo(bmp.Canvas, 0, 0); bmp.SaveToFile('test.bmp'); bmp.free;end;
xinyiman:
--- Quote from: josh on July 13, 2018, 02:14:45 pm ---No tested on Mac..
Maybe?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var bmp:tbitmap;begin bmp:=TBitmap.Create; bmp.SetSize(stringgrid1.ClientWidth,stringgrid1.ClientHeight); bmp.PixelFormat:= pf24bit; bmp.Canvas.Brush.Color := clWhite; bmp.clear; StringGrid1.PaintTo(bmp.Canvas, 0, 0); bmp.SaveToFile('test.bmp'); bmp.free;end;
--- End quote ---
Not work, return all black image %) %)
Navigation
[0] Message Index
[#] Next page