Search code examples
canvastclclipboardfile-conversion

dealing with canvas copy trouble in tcl


I created with Plotchart::createLogXYPlot in the canvas. I'm drawing several Graph in same canvas. (Using several plot in same canvas) I need this canvas to copy or convert file format type. But I'm searching about this topic, didn't help for me.

Main trouble is saved file having a clipping img.

Clipboard canvas is not working for me. (can't find tag about plotchart)

I'm trying these ways.

  1. capturing canvas to img file format (clipping trouble)

    https://nikit.tcl-lang.org/page/Img#2155d00fdc05c6b6b85fa38ed5cd7dda67fd680886245dd51b6f9bcc0ba05a5c

  2. Snapshot canvas (clipping trouble and spend many time)

    https://groups.google.com/forum/#!topic/comp.lang.tcl/Dweb1ExDKhw

  3. Clipboard canvas (didn't work)

    https://www.tcl.tk/man/tcl/TkCmd/clipboard.htm

  4. Plotchart using Saveplot (need gs(gost scripts), I will not use it, Saved .ps file is success)

    How to save Plotchart canvas other than PostScript without displaying it?

I think, fixing img clipping trouble is easiest way for me.

Output so far

Canvas convert file format: canvas convert file format Sample

Using snapshot and convert file format: using snapshot and convert file format Sample

Original graph: original graph


Solution

  • If you want to save your canvas to image, may be this example help you:

    package require Img pack [canvas .c -height 50 -width 50] .c create rectangle 0 0 25 25 -fill blue .c create rectangle 25 25 50 50 -fill green raise . ;# if there's anything over the window on-screen, it'll be obscured in the image update idletasks image create photo theCanvas -format window -data .c theCanvas write "C:\\your\\path\\here\\example.png" -format png

    (Note: the line of update isn't in the original)

    Credit: Mike Griffiths in tcl wiki

    Saludos,