Voici le code que j'utilise pour enregistrer un fichier png depuis un fichier svg. Cela fonctionne, mais j'ai aussi besoin de le sauvegarder en jpeg. Quelqu'un peut-il me conseiller sur la façon de le faire?Comment sauvegarder un jpg depuis un cairo
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());
}
}
J'ai changé l'ordre de cairo_set_source, mettant cairo_rectangle d'abord, mais je suis toujours obtenir une violation d'accès
ok, va changer mais je n'arrive même pas à ce point. Je reçois une violation d'accès sur cairo_set_source_surface. Si je mets cairo_rectangle en premier, il lance aussi – edepperson
Vous lui passez un pointeur nul. –
OK, je l'ai changé pour ceci: IntPtr pixbuf = cairo_image_surface_create (cairo_format_t.CAIRO_FORMAT_RGB24, _width, _height); mais cairo_set_source jette encore av – edepperson