Re: Gnome2::Print images.




On Jul 26, 2005, at 8:14 AM, ADIS - C.P.D. wrote:

On Jul 25, 2005, at 5:47 PM, ADIS - C.P.D. wrote:

Hello everybody,

Why I can't print a image using method "rgbimage"?

$pc->rgbimage ($pixbuf->get_pixels, $pixbuf->get_width, $pixbuf-
>get_height, $pixbuf->get_rowstride) always fails.

No errors messages are displayed, but image never appears.

[snip]

Did you ever have success after this thread?
http://mail.gnome.org/archives/gtk-perl-list/2005-April/msg00218.html

After this thread, i have posted:
http://mail.gnome.org/archives/gtk-perl-list/2005-April/ msg00222.html, and
http://mail.gnome.org/archives/gtk-perl-list/2005-April/msg00226.html

No success yet.

The API reference docs for libgnomeprint don't appear to be on developer.gnome.org. I grepped the libgnomeprint source for "rgbimage" and ran across both the gtk-doc comment and an example that prints an image.

The doc comment says:

Draws RGB color image into unit square (0,0 - 1,1) in current coordinate system. Image buffer has to be 3 bytes per pixel, order RGB, with value
  255 marking maximum and 0 minimum value.

The "unit square" thing is the key. Your code, posted in the previous thread, did a moveto, but did no translate or scale, so the image was rendered at 1/72" by 1/72" in the very lower left corner. (No kidding -- fix the errors as Emmanuele suggested in the other thread, then zoom way in on the lower left corner.) Which, i don't think, is what you wanted. :-)

What you need, instead of moveto and rgbimage, is gsave, translate, scale, rgbimage, grestore. (Wow, that postscript hacking actually comes in handy!)

Here's a hacked-up version of your previous code, with Emmanuele's fixes and several of my own, that prints something. Just substitute your own image for "foshizzle.png".


-=-=-=-=-=-
#!/usr/bin/perl -w
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
use Gnome2::Print;

my $job = Gnome2::Print::Job->new;
my $config = Gnome2::Print::Config->default;
my $context = $job->get_context;

$context->beginpage("1");

my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file ('foshizzle.png');

# rgbimage draws an image "in a unit square in the current coordinate
# system."  thus, in order to draw it at any decent size, we need to
# transform and scale.
$context->gsave;
my ($page_width, $page_height) = $config->get_page_size;
$context->translate (($page_width - $pixbuf->get_width) / 2,
             ($page_height - $pixbuf->get_height) / 2);
$context->scale ($pixbuf->get_width, $pixbuf->get_height);
$context->rgbimage ($pixbuf->get_pixels, $pixbuf->get_width,
            $pixbuf->get_height, $pixbuf->get_row_stride);
$context->grestore;

# alright, now we're finished.
$context->showpage;
$job->render ($context);
$job->close;

my $preview = Gnome2::Print::JobPreview->new ($job, 'Preview Window');
$preview->show;
$preview->signal_connect (destroy => sub {Gtk2->main_quit});

Gtk2->main;
-=-=-=-=-=-



--
To me, "hajime" means "the man standing opposite you is about to hit you with a stick".
  -- Ian Malpass, speaking of the Japanese word for "the beginning"




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]