2
다음은 svg 파일에서 png를 저장하는 데 사용하는 코드입니다. 작동하지만 jpeg로 저장해야합니다. 누군가이 일을하는 방법에 대해 조언 할 수 있습니까?카이로에서 jpg를 저장하는 방법
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_rectangle을 가하고, cairo_set_source의 순서를 변경했습니다,하지만, 난 여전히 액세스 위반
좋아, 변경 될 것이지만 나는 그 시점에 도달하지 못하고있다. cairo_set_source_surface에 액세스 위반이 있습니다. cairo_rectangle을 먼저 넣으면 av를 던져줍니다. – edepperson
null 포인터를 전달하고 있습니다. –
좋아요, 다음과 같이 변경했습니다 : IntPtr pixbuf = cairo_image_surface_create (cairo_format_t.CAIRO_FORMAT_RGB24, _width, _height); 하지만 cairo_set_source는 여전히 – edepperson