문제

내가 하려고 했는데 변환하 SVG PNG 이미지를 사용하여 C#작성하지 않고도,너무 많은 코드입니다.할 수 있는 사람이 추천한 라이브러리 또는 예제 코드는 이것을 하고 있는가?

도움이 되었습니까?

해결책

호출할 수 있는 명령줄 버전의 잉크스케이프 이렇게하려면:

http://harriyott.com/2008/05/converting-svg-images-to-png-in-c.aspx

또한 C#SVG rendering engine,주로 할 수 있도록 설계되 SVG 파일에 사용할 수 있는 웹에 codeplex 는 사용자의 요구에 적합할 수 있습는 경우는 문제입니다:

원래는 프로젝트
http://www.codeplex.com/svg

포크와 함께 수정하고 더 많은 행동: (추가 7/2013)
https://github.com/vvvv/SVG

다른 팁

이 훨씬 쉬운 방법이 사용하는 라이브러리 http://svg.codeplex.com/ (새 버전@GIT, @NuGet).여기에 내 코드

var byteArray = Encoding.ASCII.GetBytes(svgFileContents);
using (var stream = new MemoryStream(byteArray))
{
    var svgDocument = SvgDocument.Open(stream);
    var bitmap = svgDocument.Draw();
    bitmap.Save(path, ImageFormat.Png);
}

를 했을 때 래스터 svgs 서버에서,I ended up P 를 사용하여/호출 전화 librsvg 기능을(당신을 얻을 수 있습니 dll windows 버전의 GIMP 이미지 편집 프로그램).

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetDllDirectory(string pathname);

[DllImport("libgobject-2.0-0.dll", SetLastError = true)]
static extern void g_type_init(); 

[DllImport("librsvg-2-2.dll", SetLastError = true)]
static extern IntPtr rsvg_pixbuf_from_file_at_size(string file_name, int width, int height, out IntPtr error);

[DllImport("libgdk_pixbuf-2.0-0.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
static extern bool gdk_pixbuf_save(IntPtr pixbuf, string filename, string type, out IntPtr error, __arglist);

public static void RasterizeSvg(string inputFileName, string outputFileName)
{
    bool callSuccessful = SetDllDirectory("C:\\Program Files\\GIMP-2.0\\bin");
    if (!callSuccessful)
    {
        throw new Exception("Could not set DLL directory");
    }
    g_type_init();
    IntPtr error;
    IntPtr result = rsvg_pixbuf_from_file_at_size(inputFileName, -1, -1, out error);
    if (error != IntPtr.Zero)
    {
        throw new Exception(Marshal.ReadInt32(error).ToString());
    }
    callSuccessful = gdk_pixbuf_save(result, outputFileName, "png", out error, __arglist(null));
    if (!callSuccessful)
    {
        throw new Exception(error.ToInt32().ToString());
    }
}

내가 사용하는 바틱 니다.완전한 델피 코드:

procedure ExecNewProcess(ProgramName : String; Wait: Boolean);
var
  StartInfo : TStartupInfo;
  ProcInfo : TProcessInformation;
  CreateOK : Boolean;
begin
  FillChar(StartInfo, SizeOf(TStartupInfo), #0);
  FillChar(ProcInfo, SizeOf(TProcessInformation), #0);
  StartInfo.cb := SizeOf(TStartupInfo);
  CreateOK := CreateProcess(nil, PChar(ProgramName), nil, nil, False,
              CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS,
              nil, nil, StartInfo, ProcInfo);
  if CreateOK then begin
    //may or may not be needed. Usually wait for child processes
    if Wait then
      WaitForSingleObject(ProcInfo.hProcess, INFINITE);
  end else
    ShowMessage('Unable to run ' + ProgramName);

  CloseHandle(ProcInfo.hProcess);
  CloseHandle(ProcInfo.hThread);
end;

procedure ConvertSVGtoPNG(aFilename: String);
const
  ExecLine = 'c:\windows\system32\java.exe -jar C:\Apps\batik-1.7\batik-rasterizer.jar ';
begin
  ExecNewProcess(ExecLine + aFilename, True);
end;

을 추가하여 응답에서@아니 쉬는 경우에,당신이하는 데 문제가 있으로 보지 않는 텍스트로 내보낼 때 SVG 이미지를 만들 수 있습니다,재귀적 기능을 반복을 통해 아이들의 SVGDocument,을 캐스팅하려고 그것을 SvgText 가능한 경우(추가 자신의 오류를 검사하)과정으로 로그인하여 가족과 스타일입니다.

    foreach(var child in svgDocument.Children)
    {
        SetFont(child);
    }

    public void SetFont(SvgElement element)
    {
        foreach(var child in element.Children)
        {
            SetFont(child); //Call this function again with the child, this will loop
                            //until the element has no more children
        }

        try
        {
            var svgText = (SvgText)parent; //try to cast the element as a SvgText
                                           //if it succeeds you can modify the font

            svgText.Font = new Font("Arial", 12.0f);
            svgText.FontSize = new SvgUnit(12.0f);
        }
        catch
        {

        }
    }

알려면 질문이 있습니다.

당신이 사용할 수 있습 altsoft xml2pdf lib 이

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top