[英]How do I save a jpg from a cairo
以下是我用來從svg文件保存png的代碼。 可行,但我還需要將其另存為jpeg。 有人可以建議我如何做嗎?
private void RasterizeSvg(string tempsvg, string rsltPath, int _width, int _height)
{
bool callSuccessful = SetDllDirectory(@"C:\ProgramDownloads\librsvg\librsvg-dev_2.32.1-1_win32\bin");
if (!callSuccessful)
{
throw new Exception("Could not set DLL directory");
}
g_type_init();
IntPtr error;
IntPtr rsvghandle = rsvg_handle_new_from_file(tempsvg, out error);
if (error != IntPtr.Zero)
{
throw new Exception(Marshal.ReadInt32(error).ToString());
}
IntPtr cairosurface = cairo_image_surface_create(cairo_format_t.CAIRO_FORMAT_RGB24, _width, _height);
IntPtr cairorenderer = cairo_create(cairosurface);
bool brslt = rsvg_handle_render_cairo(rsvghandle, cairorenderer);
//cairo_surface_write_to_png(cairosurface, rsltPath);
IntPtr pixbuf = IntPtr.Zero;
cairo_set_source_surface(pixbuf, cairosurface, 0, 0);
cairo_rectangle(pixbuf, 0, 0, _width, _height);
cairo_fill(pixbuf);
callSuccessful = gdk_pixbuf_save(pixbuf, rsltPath, "jpg", out error, __arglist(""));
if (!callSuccessful)
{
throw new Exception(error.ToInt32().ToString());
}
}
我已經更改了cairo_set_source的順序,將cairo_rectangle放在首位,但是仍然遇到訪問沖突
您正在將一個空的pixbuf指針傳遞給cairo_set_source_surface。 你應該通過這樣的事情...
IntPtr pixbuf = cairo_create(cairosurface);
也
gdk_pixbuf_save的第三個參數應為“ jpeg”
也許您也應該初始化錯誤?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.