Re: how i can normal repaint image??
- From: muppet <scott asofyet org>
- To: gtk-perl list <gtk-perl-list gnome org>
- Subject: Re: how i can normal repaint image??
- Date: Sun, 30 May 2004 14:46:49 -0400
On Thursday, June 3, 2004, at 05:44 PM, dmitriyk wrote:
When I press on the button, I want, that the new picture was shown on
the old place. But the new picture all time moves on the left, closing
thus an initial picture. What do I do not so?
First, you are using Gtk-Perl / gtk+ 1.x to write new code. Don't do
that, both are obsolete by two years, and Gtk-Perl is not actively
maintained. Please use Gtk2-Perl with gtk+ 2.x.
In porting your code to Gtk2-Perl you'll be using Gtk2::Gdk::Pixbuf
instead of Gtk2::Gdk::Imlib. While it sounds like a pain to have to
learn a new API, it's actually quite a lot simpler.
To put raw image data from a perl array onto the screen, you'd use a
Gtk2::Image instead of a Gtk2::Pixmap, and set a Gtk2::Gdk::Pixbuf into
that Gtk2::Image. You can create the Pixbuf quite easily with
$pixbuf = Gtk2::Gdk::Pixbuf->new_from_data
($image_data, # packed image data in a scalar
'rgb', # only 24- or 32-bit RGB are supported
FALSE, # no alpha, data is 24-bit
8, # only 8 bits per sample are supported
$width, # in pixels
$height, # in pixels
$rowstride); # number of *bytes* in each row
# (to allow for alignment padding)
# now tell the Gtk2::Image to use that pixbuf
$image->set_from_pixbuf ($pixbuf);
I don't know about you, but i think that's a hell of a lot easier than
all the weird Imlib+Gdk stuff your code was having to do. :-)
GdkPixbuf also does file loading and saving, and you can get all of the
pixel data with $pixbuf->get_pixels, so if you wanted to work on color
data, you could actually remove your dependency on Image::Magick. That
said, GdkPixbuf only deals with RGB data, so you'd have to do the RGB
to gray and gray to rgb conversions yourself.
Now, to answer your actual question:
sub second{
$cc++;
[snip]
$pixmap = new Gtk::Pixmap( $gdk_pixmap, $mask );
$pixmap->show();
$fixed = new Gtk::Fixed();
$fixed->set_usize( $w, $h );
$fixed->put( $pixmap, 0, 0 );
#$hbox->add( $fixed );
$hbox->pack_end( $fixed, 0, 0, 0 );
$fixed -> show() if $cc%2!=0;
do{
$fixed -> hide();
$image=undef;
$gdk_pixmap=undef;
} if $cc%2==0;
}
This is your problem. You are simply doing pack-end on each one, and
building up more and more pictures from the right side (with odd modulo
math that keeps every other one from showing up). There's no need to
do that -- what you should really do is store a reference to the image
container for each of the left and right images, and just tell those
containers to use new data.
In your code, that would be:
$right_image = new Gtk::Pixmap ($gdk_pixmap, $mask);
...
# later, when updating:
$right_image->set ($gdk_pixmap, $mask);
and in Gtk2 (which i strongly recommend) you'd do
# you can create it and do layout without having any data in it
$right_image = new Gtk2::Image;
...
# when you need to set the image data:
$right_image->set_from_pixbuf ($pixbuf);
Thank you!
no problem.
--
She's obviously your child. She looks like you, she talks a lot, and
most of it is gibberish.
-- Elysse, to me, of Zella.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]