如何将整个可滚动画布另存为 PNG?

发布于 2024-10-31 12:19:19 字数 321 浏览 6 评论 0原文

我有一个可滚动的画布,我想要将其内容放入 png 图像中。

问题是我只得到了画布的照片,缺少画布在给定时间的不可见部分。

如何将整个可滚动画布转换为 png 图像?

我当前的代码如下:

my $canvas_to_get_photo=$mw->Photo(-format=>'Window', -data=>oct($canvas_to_get->id));
$canvas_to_get_photo->write('somepath/image.png', -format=>'png');

I have a scrollable canvas who's content i want into a png image.

The problem is I only get a photo of the canvas, missing the non visible part of the canvas at that given time.

How do i get the whole scrollable canvas into a png image?

My current code is the following:

my $canvas_to_get_photo=$mw->Photo(-format=>'Window', -data=>oct($canvas_to_get->id));
$canvas_to_get_photo->write('somepath/image.png', -format=>'png');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕色琉璃 2024-11-07 12:19:19

没有一种本地方法可以做到这一点; Tk 仅绘制窗口,而不绘制基于图像的表面。因此,您的选择是:

  1. 滚动画布,拍摄快照,然后将它们拼接在一起
  2. 生成封装的后记(如果您使用正确的选项,它确实支持遍历整个画布)并生成图像使用像 Ghostscript 这样的工具。

There isn't a native way to do it; Tk only paints to windows, not to image-based surfaces. Your options are therefore to either:

  1. scroll the canvas, taking snapshots, and then stitch them together
  2. generate encapsulated postscript (which does support going over the whole canvas, provided you use the right options) and generate your image from that with a tool like ghostscript.
独夜无伴 2024-11-07 12:19:19

我已经有一段时间没有做过任何繁重的 Tk 工作了,所以这可能行不通。您是否尝试过寻找滚动画布的非滚动子组件。

IIRC,每个“滚动”小部件实际上是一个“大型小部件”,带有滚动条、角项和滚动项子小部件。

所以,这可能是你想要的

my $canvas = $scrolled->Subwidget('widget');
$canvas = $scrolled unless $canvas;
my $canvas_id = $canvas->id;

my $photo = $mw->Photo(-format => 'Window', -data => oct $canvas_id );
$photo->write('somepath/image.png', -format => 'png' );

It's been a awhile since I did any heavy Tk work, so this may not work. Have you tried looking for the non-scrolled subcomponent of the scrolled canvas.

IIRC, each 'Scrolled' widget is actually a "mega-widget", with scrollbars, a corner item, and a scrolled item sub-widgets.

So, it may be that you want

my $canvas = $scrolled->Subwidget('widget');
$canvas = $scrolled unless $canvas;
my $canvas_id = $canvas->id;

my $photo = $mw->Photo(-format => 'Window', -data => oct $canvas_id );
$photo->write('somepath/image.png', -format => 'png' );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文