Re: how to get the color of a pixel(x,y) on the window?



 				
I have tried your method,but the line color is still different from the pixel get from the .png picture on the window.
Below is the code:

 pixbuf=Gdk::Pixbuf::create_from_file("color.png");
 int width, height, rowstride, n_channels;
 guint8 *pixels, *p;
 n_channels= pixbuf->get_n_channels();   
 width = pixbuf->get_width();
 height = pixbuf->get_height();
 rowstride = pixbuf->get_rowstride();
 pixels= pixbuf->get_pixels();
 p = pixels + y* rowstride + x * n_channels;

gushort red   = p[0] * 0x0101u;
gushort green = p[1] * 0x0101u;
gushort blue  = p[2] * 0x0101u;

Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();  
  
cr->set_source_rgb(65535,65535,65535);    //paint the background of the canvas
cr->paint();

cr->set_source_rgb(red,green,blue);    //draw line,it's color get from the pixel of above png picture
cr->set_line_width(2);
cr->move_to(0,0);
cr->line_to(100,100);
cr->stroke();



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