GTK rotating image (pixbuf) patch

Source: Internet
Author: User
Tags cairo gtk

You must insert an image in the project and rotate it at any angle. The GTK version I used is windows32bit 2.24, which is from the official website. In this version of API, the rotate pixbuf API has only one simple function that rotates at a factor of 90 °: gdk_pixbuf_rotate_simple (), there is no function to rotate any angle. After one day, Google finally solved the problem. The method is as follows:

Step 1.

Found this bug, his attachment achieves arbitrary rotation angle, but this attachment file is incomplete, I added a gdk-pixbuf-private.h file (from here ). And modified the # include statement of these files, because the patch provided by him was originally used to compile GTK, but the gtk I used has been compiled and cannot be re-compiled by myself, therefore, you must change the # include statement to use this patch as the code of your project.

Step 2.

Put the. c. H files in the patch in the same make directory and compile and run the demo that comes with the patch. The test result is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4C/B6/wKiom1REX9CQbl4uAARB3o-HNYw399.jpg "Title =" image.jpg "alt =" wKiom1REX9CQbl4uAARB3o-HNYw399.jpg "/>

Is the result of running the image of the demo menu, it works!


Patch API description:

Gdk_pixbuf_rotate_matrix _ starts with some matrix tool methods, which are not important.

The most important thing is this function.

void gdk_pixbuf_rotate(GdkPixbuf*dst, gdoubledst_x, gdoubledst_y, gdouble*matrix, GdkPixbuf*src, gdoublesrc_center_x, gdoublesrc_center_y, gint*result_rect_x, gint*result_rect_y, gint*result_rect_width, gint*result_rect_height, GdkInterpTypeinterp_type);


This function converts SRC pixbuf through rotate matrix and writes it to DST pixbuf. The parameters starting with result_rect _ should be the values written by the function. I haven't used them yet. The call method can be found in the demo, or my code snippets:

MyPicture *picture = MY_PICTURE(self);MyPicturePrivate* priv = MY_PICTURE_GET_PRIVATE (picture);GdkRectangle rect;if (priv->pixbuf) {    gdouble m[4];    gdouble angle = 45./180*PI;    gdk_pixbuf_rotate_martix_fill_for_rotation(m, angle);    gdk_pixbuf_rotate_matrix_mult_number(m, 1.);    gdk_pixbuf_rotate (priv->pixbuf,        picture->width/2,        picture->height/2,        m,        priv->orignPixbuf,        picture->orignWidth/2,        picture->orignHeight/2,        &rect.x,         &rect.y,         &rect.width,         &rect.height,        GDK_INTERP_NEAREST);        gdk_draw_pixbuf (appState->pixmap,        appState->drawingArea->style->white_gc,        priv->pixbuf,        0,        0,        picture->x + appState->orignX,        picture->y + appState->orignY,         picture->width,        picture->height,        GDK_RGB_DITHER_NORMAL, 0, 0);}

Which of the following has found a better solution? Please leave a message. Thank you ~


PS: Cairo is not used to process images, because Cairo turns black in transparent areas of my project when processing PNG (unknown reason, I used Cairo to draw images on pixmap), and Cairo only supports PNG, JPG, and so on. Therefore, Cairo is not required to draw images.

This article is from "some" blog, please be sure to keep this source http://2924037.blog.51cto.com/2914037/1565768

GTK rotating image (pixbuf) patch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.