[cairo] Trouble resizing (scaling) an XImage

Taekyun Kim podain77 at gmail.com
Mon Jun 27 08:43:32 PDT 2011


I think you did integer division. Something like "(double)width / (double)xImage->width" might solve your problem.

2011. 6. 28. 오전 12:05 Justin Anderson <justin at rayonix.com> 작성:

> I should mention that the source image is an 8 bit grayscale.  Thanks.
> 
> 
> On Mon, Jun 27, 2011 at 10:00 AM, Justin Anderson <justin at rayonix.com> wrote:
> Hello,
> 
> I'm trying to resize an X11 XImage which is a 640x480 pixel image from a video grabber, to be displayed on a window in an X11/Motif application.
> 
> If I comment out the scale command in the following code, the image is displayed fine, albeit clipped on my window.  If I uncomment the scale operation, there is no image in the window.
> 
> Any ideas?  Thanks!
> 
> 
> 
>    //Create a simple X11 window for displaying the XImage...
>    window = XCreateSimpleWindow(
>       display,
>       RootWindowOfScreen(screen),
>       0, // x
>       0, // y
>       width,
>       height,
>       0,                          // border width
>       BlackPixelOfScreen(screen), // border
>       BlackPixelOfScreen(screen)  // background
>    );
>    XMapRaised(display, window);
>    
>    //cairo stuff...
>    cairo_surface_t *surface_dest = cairo_xlib_surface_create(display, window, XDefaultVisualOfScreen(screen), width, height);
>    cairo_t *cr_dest = cairo_create(surface_dest);
>    
>    cairo_surface_t *surface_source = cairo_image_surface_create_for_data((unsigned char*)(xImage->data), CAIRO_FORMAT_RGB24, xImage->width, xImage->height, xImage->bytes_per_line);
> 	 
>    cairo_scale(cr_dest, width / xImage->width, height / xImage->height);
> 
>    cairo_set_source_surface(cr_dest, surface_source, 0, 0);
>    cairo_paint(cr_dest);
>    cairo_surface_destroy(surface_source);
> 
>    //Put the scaled XImage on the window...
>    XPutImage(display, window, gc, xImage, 0, 0, 0, 0, width, height);
> 	
>    cairo_surface_destroy(surface_dest);
>    cairo_surface_destroy(surface_source);
> 
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20110628/8daa1a7d/attachment.htm>


More information about the cairo mailing list