#!/usr/bin/perl -w use strict; use warnings; use Gtk2 '-init'; use Image::Magick; ## # Brücke von Image::Magic nach GTK2 ## sub magick_to_pixbuf($) { my ($magick)=@_; my $depth=8; my $alpha=1; my @data=$magick->ImageToBlob(magick=>$alpha?'RGBA':'RGB', colorspace=>'RGB', depth=>$depth); my $b=$magick->Get('columns'); my $h=$magick->Get('rows'); return data_to_pixbuf($data[0],$h,$b,$alpha,$depth) } ## # BiteString nach GTK2 ## sub data_to_pixbuf($$$$$) { my ($data,$h,$b,$alpha,$colors)=@_; my $c=($colors*($alpha?4:3))/8; return Gtk2::Gdk::Pixbuf->new_from_data ($data,'GDK_COLORSPACE_RGB',$alpha,$colors,$b,$h,$b*$c); } ## # Defaultbild erzeugen ## sub create_image($) { my ($img) = @_; $img->Set(size=>'100x100'); $img->Read('xc:none'); $img->Draw(fill=>'black', stroke=>"black", primitive=>'circle', points=>'50,50 2,50'); $img->Draw(fill=>'white', stroke=>"black", primitive=>'circle', points=>'50,50 5,50'); $img->Annotate(text=> '!', stroke=>"red", fill=>"red", x=>35, y=>85, pointsize=>100, font=>"arial"); } ################################################################### my $images = Image::Magick->new; create_image($images); my $pixbuf = magick_to_pixbuf($images); my $window = Gtk2::Window->new; my $image = Gtk2::Image->new_from_pixbuf ($pixbuf); $window->add($image); $window->set_title("Test"); $window->show_all; $window->signal_connect (delete_event => sub {Gtk2->main_quit;}); Gtk2->main; exit(0);