2

以下は、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 を先頭に変更しましたが、アクセス違反が発生します。

4

1 に答える 1

0

null pixbuf ポインターを cairo_set_source_surface に渡しています。このようなものを渡す必要があります...

IntPtr pixbuf = cairo_create (cairosurface);

また

gdk_pixbuf_save の 3 番目の引数は「jpeg」にする必要があります

エラーも初期化する必要がありますか?

于 2012-10-01T14:08:48.003 に答える