Hi, when I first encountered this, I was told( by a Perl/Tk expert) that the Photo object wants base64_encoded data, and the -file=> option, does convert the binary data to base64 internally as it is read from the disk. So I don't think there is anyway around it.

However, if you are willing to switch to Perl/Gtk2, you can load binary data. There may still be a bit of a slowdown though, because the Gtk2 pixbuf wants all images to be 8-bit 'rgb' (+ optional alpha), so the pixbuf loader converts all images to 24bit or 32 bit data. Here is a simple example:

#!/usr/bin/perl use strict; use warnings; use Gtk2 '-init'; use GD; use GD::Text::Align; my $time= localtime; my $image = new GD::Image(200,30); my $black = $image->colorAllocate(0,0,0); my $white = $image->colorAllocate(255,255,255); my $text = new GD::Text::Align( $image, font => gdLargeFont, # font => './arial.ttf', text => $time, color => $white, valign => "center", halign => "center", ); # the order of these two lines is important $image->filledRectangle( 15, 15, 150, 150, $black ); $text->draw(100,15); my $gdimage; open( IMAGE, ">",\$gdimage) || die "$!\n"; binmode( IMAGE ); print IMAGE $image->png(); close IMAGE; #gtk2 stuff my $mw = Gtk2::Window->new; my $vp = Gtk2::Viewport->new(undef, undef); $mw->add($vp); &load_image; $mw->signal_connect('destroy', sub { Gtk2->main_quit }); Gtk2->main; ########################################################### sub load_image { my $loader = Gtk2::Gdk::PixbufLoader->new; $loader->write ($gdimage); $loader->close; my $pixbuf = $loader->get_pixbuf; my $image = Gtk2::Image->new_from_pixbuf ($pixbuf); # my $pb = $image->get_pixbuf; # my ($x, $y) = ($pb->get_width, $pb->get_height); # $mw->set_title("dim ${x}x${y}"); $vp->add($image); $mw->show_all(); }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Tk:Photo -data with binary data? by zentara
in thread Tk:Photo -data with binary data? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.