Re: Can't copy the right image from window
- From: Tigran Piloyan <tigran piloyan gmail com>
- To: gtk-list gnome org
- Subject: Re: Can't copy the right image from window
- Date: Wed, 16 Jun 2010 07:38:05 -0000
Please use this command to build
gcc `pkg-config --cflags gtk+-2.0 --libs gtk+-2.0 glib-2.0 gthread-2.0` app_name.c
On Wed, Jun 16, 2010 at 12:35 PM, Tigran Piloyan
<tigran piloyan gmail com> wrote:
Hi, i tried to copy from the GdkWindow an image with the function gdk_drawable_copy_to_image() but everytime i get different images under Ubuntu with gnome, in KDE it allways copied the right image . I tried to set USE_XFT = 0 to disable antialiasing, but it didn't help.
#include <gtk/gtk.h>
#include <glib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
GdkWindow *window = NULL;
GdkWindowAttr attr;
GdkRectangle rectangle;
GdkColormap *colormap = NULL;
GdkImage *image = NULL;
GdkGC *gc = NULL;
GdkColor color;
GError *err = NULL;
gchar *buffer;
gsize count;
GdkPixbuf *pixbuf = NULL;
gtk_init(&argc, &argv);
colormap = gdk_colormap_get_system();
if(colormap == NULL)
{
printf("Unable to create a GdkColormap,gdk_colormap_get_system returns NULL.");
return 1;
}
rectangle.x = 0;
rectangle.y = 0;
rectangle.width = 300;
rectangle.height = 300;
attr.title = "Window";
attr.x = 0;
attr.y = 0;
attr.width = 500;
attr.height = 600;
attr.wclass = GDK_INPUT_OUTPUT;
attr.window_type = GDK_WINDOW_TOPLEVEL;
window = gdk_window_new(NULL, &attr, GDK_WA_X | GDK_WA_Y |GDK_WA_TITLE);
if(window == NULL)
{
printf("The gdk_window_new function returned NULL, unable to create GdkWindow.");
return 1;
}
gdk_window_show(window);
gdk_flush();
sleep(3);
gc = gdk_gc_new(window);
if(gc == NULL)
{
printf("Unable to create a GdkGC, gdk_gc_new returns NULL.");
return 1;
}
color.red = 100 * (65535 / 255);
color.green = 50 * (65535 / 255);
color.blue = 100 * (65535 / 255);
gdk_gc_set_rgb_fg_color(gc, &color);
gdk_window_begin_paint_rect(window, &rectangle);
gdk_draw_rectangle(window, gc, TRUE, 0, 0, 200, 200);
gdk_window_end_paint(window);
image = gdk_drawable_copy_to_image(window, NULL, 0, 0, 0, 0, attr.width, attr.height);
if(image == NULL)
{
printf("Unable to create a GdkImage, gdk_drawable_copy_to_image returns NULL.");
return 1;
}
pixbuf = gdk_pixbuf_get_from_image (NULL, image, colormap, 0, 0, 0, 0, attr.width, attr.height);
if(pixbuf == NULL)
{
printf("Unable to create a GdkPixbuf, gdk_pixbuf_get_from_image returns NULL.");
return 1;
}
gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &count, "jpeg", &err, "quality", "100", NULL);
gdk_pixbuf_save(pixbuf, "window_image.jpg", "jpeg", &err, "quality", "100", NULL);
sleep(3);
return 0;
}
The image saved in window_image.jpg doesn't match with drawn on window image
--
Tigran Piloyan
Linux Verification Center, ISPRAS, RAU
web: http://www.linuxtesting.org
e-mail: tigran piloyan linuxtesting org
--
Tigran Piloyan
Linux Verification Center, ISPRAS, RAU
web:
http://www.linuxtesting.orge-mail:
tigran piloyan linuxtesting org
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]