2
我正在寫需要做下面的一個小演示應用程序保存PNG圖像:由度 x個旋轉和使用開羅
- 閱讀參考
PNG
圖像文件 - 旋轉
PNG
圖像 - 將新圖像保存爲動畫的框架
- 隨着上次旋轉的結果返回到步驟2,直到完成旋轉。
結果應該是一系列PNG
圖像文件,以不同的旋轉角度顯示圖像。這些圖像然後將以某種方式組合成電影或動畫GIF
。
我創建了下面的代碼,它試圖做一個旋轉:
#include <cairo.h>
#include <math.h>
/**** prototypes *******/
void Rotate(cairo_surface_t *image, int degress, const char *fileName);
double DegreesToRadians(double degrees);
/***********************/
double DegreesToRadians(double degrees)
{
return((double)((double)degrees * ((double)M_PI/(double)180.0)));
}
void Rotate(cairo_surface_t *image, int degrees, const char *fileName)
{
int w, h;
cairo_t *cr;
cr = cairo_create(image);
w = cairo_image_surface_get_width (image);
h = cairo_image_surface_get_height (image);
cairo_translate(cr, w/2.0, h/2.0);
cairo_rotate(cr, DegreesToRadians(degrees));
cairo_translate(cr, - w/2.0, -h/2.0);
cairo_set_source_surface(cr, image, 0, 0);
cairo_paint (cr);
cairo_surface_write_to_png(image, fileName);
cairo_surface_destroy (image);
cairo_destroy(cr);
}
int main()
{
cairo_surface_t *image = cairo_image_surface_create_from_png ("images/begin.png");
Rotate(image, 90, "images/end.png");
return(0);
}
的問題是原始圖像的90度旋轉後,所產生的保存的圖像旋轉,但並不完全正確。我試過重新排列cairo
的調用順序,認爲它可能與表面狀態或環境有關。
的開始和結束圖片如下:
我缺少什麼?
非常感謝。我感謝幫助,並認爲我明白我做錯了什麼。 – Chimera 2012-08-06 21:12:52