我有一些代碼,看起來像這樣:如何使用cairo將圖像寫入SVG文件?
cairo_surface_t * surface = cairo_svg_surface_create("0.svg", 512, 512);
cairo_t * context = cairo_create(surface);
int * data = new int[512*512];
// fill the data...
cairo_surface_t * image_surface =
cairo_image_surface_for_data(data, 512, 512, 512*4);
cairo_set_source_surface(context, image_surface, 0, 0);
cairo_paint(context);
// do some other drawing ...
cairo_surface_flush(surface);
cairo_surface_finish(surface);
cairo_surface_destroy(surface);
cairo_destroy(context);
然而,SVG總是出現損壞。圖像寫入不正確,下面的所有繪圖命令都不起作用。將表面類型更改爲PS,即:
cairo_surface_t * surface = cairo_ps_surface_create("0.ps", 512, 512);
產生完全正確的PS文檔。 任何幫助修復SVG將不勝感激。
編輯:忘了提供版本信息。 cairo_version_string()給出的開羅1.10.2。 G ++ 4.52 運行在Ubuntu 11.04
EDIT(2):好吧,我跟開羅追查下來到PNG問題,發現如預期要麼cairo_surface_write_to_png不行爲。這個函數和嘗試在SVG中嵌入圖像都會導致「內存不足錯誤」,我仍然不知道爲什麼。
謝謝,但這不能解決問題。看我的文章編輯。 – Scott
好的。看看你的版本,這應該是'CAIRO_SVG_VERSION_1_1'。在PNG問題上,你可以'cairo_image_surface_create_from_png()',然後將曲面寫回新的PNG並讓文件損壞?或者這可以正常工作? – Seth