Forum > LCL
[SOLVED] Image Canvas Save
Pe3s:
Hello forum users, I have a TImage component on the form, a picture in it, I write text on the canvas, how can I save the whole thing to a file?
--- 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.Edit1Change(Sender: TObject);begin with Image1.Canvas do begin Font.Color := clBlack; Font.Size := 13; Brush.Style := bsClear; Refresh; Repaint; TextOut(33, 13, Edit1.Text); end;end;
Pe3s:
If I change to Image1.Picture.Bitmap.Canvas, the text becomes gray and illegible.
--- 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.Edit1Change(Sender: TObject); begin with Image1.Picture.Bitmap.Canvas do begin Font.Color := clBlack; Font.Size := 13; Brush.Style := bsClear; Refresh; Repaint; TextOut(33, 13, Edit1.Text); end; end;
howardpc:
Here's one possible way:
--- 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.Edit1Change(Sender: TObject);var pic: TPicture = Nil;begin Image1.Canvas.Font.Color := clBlack; Image1.Canvas.Font.Size := 13; Image1.Canvas.Brush.Style := bsClear; Image1.Canvas.TextOut(33, 13, Edit1.Text); pic := TPicture.Create; try pic.Bitmap.SetSize(Image1.Width, Image1.Height); pic.Bitmap.Canvas.CopyRect(Rect(0, 0, pic.Width, pic.Height), Image1.Canvas, Rect(0, 0, Image1.Width, Image1.Height)); pic.SaveToFile('test.png'); finally pic.Free; end;end;You would probably want to show an OpenDialog window to choose where to save the file, but I leave that for you to implement.
Pe3s:
@howardpc Thank you :)
I have one more question how can I print Timage with Canvas text ?
howardpc:
All things are possible...
Printing or saving a file in the middle of an edit OnChange event is not good practice. So I attach a little project which shows one way to print an image overlaid with text inserted from an edit control. Printing is triggered by a button click rather than an OnChange event.
Since most printers are high resolution the text is likely to be pixellated in the printed output.
Navigation
[0] Message Index
[#] Next page