Re: Scaling an image with Gtk2::Gdk::Pixbuf->scale

Try creating a new (empty) image of the required size and then use cairo to fill it with the desired contents. The following link may help you (though it is in C and not perl, but the API is the same):
I don't know any C, but as far as I can tell, the Perl equivalent of draw_in_a_GdkPixbuf.c should be something like this. (I can't tell how to make it work.)
package scaleme;
use strict;
use diagnostics;
use warnings;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
use Cairo;
# Display this image
my $path = 'change_this_directory/cat.bmp';
# Open a Gtk2 window with a Gtk2::TextView
my $window = Gtk2::Window->new('toplevel');
$window->set_default_size(800, 600);
$window->signal_connect('delete-event' => sub {
my $frame = Gtk2::Frame->new();
my $scrollWin = Gtk2::ScrolledWindow->new(undef, undef);
$scrollWin->set_policy('automatic', 'automatic');     
my $textView = Gtk2::TextView->new;
if (-e $path) {
    my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($path);
    my $w = $pixbuf->get_width();
    my $h = $pixbuf->get_height();
    my $surface = Cairo::ImageSurface->create('argb32', $w, $h);
    my $cr = Cairo::Context->create($surface);

    # Neither of the following two lines work
#   $cr->set_source_pixbuf($pixbuf, 0, 0);
    Gtk2::Gdk::Cairo->set_source_pixbuf($cr, $pixbuf, 0, 0);
    # Continuing...
    my $buffer = $textView->get_buffer();

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