Capturing a widget bitmap

View: New views
1 Messages — Rating Filter:   Alert me  

Capturing a widget bitmap

by Jose Leon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
  I want to capture a widget bitmap and save it to disk, I can do it
without any problem if the widget is shown on screen, but I would like
to do it without being shown, so I can build it on the background.

This code do the job, but on Vista, not in XP, that is, it creates a
window off screen and captures the bitmap, but the same code on XP it
creates a black bitmap:

<?php

if (!class_exists('gtk')) {
    die("Please load the php-gtk2 module in your php.ini\r\n");
}

$btnLogin    = new GtkCalendar();

$wnd = new GtkWindow();
$wnd->set_decorated(false);
$wnd->set_skip_taskbar_hint(false);
$wnd->move(-1000,-1000);
$wnd->add($btnLogin);
$wnd->show_all();
savewidgetbitmap($btnLogin, 't.bmp');


function savewidgetbitmap($widget, $filename)
{
  $widget->show();
  while (Gtk::events_pending())
  {
    Gtk::main_iteration();
  }

  $window= $widget->window;
  list($width, $height)=$window->get_size();

  $pixbuf = new GdkPixbuf(Gdk::COLORSPACE_RGB, TRUE, 8, $width, $height);

  $pixbuf->get_from_drawable ($widget->window,
$widget->window->get_colormap(), 0, 0, 0, 0, $width, $height);

  $pixbuf->save($filename,'bmp');

}

?>

Any other method that works on Vista and XP?

Thanks in advance.

Regards

--
PHP-GTK General Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php