【问题标题】:how to render svg file in iphone and ipad如何在 iphone 和 ipad 中渲染 svg 文件
【发布时间】:2010-11-23 12:24:50
【问题描述】:

我编写了代码来显示任何类型的文件,例如 pdf、svg 等。但不幸的是,我的代码仅适用于 pdf。代码是这样的

-(void)drawRect : (CGRect)rect {
CGPDFPageRef myPage;
NSString * pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@ "pdfdoc" ofType:@ "pdf"];
NSURL * pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
// NSLog(@"%@",pdfUrl);
CGPDFContentStreamRef myContentStream;
document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
// NSLog(@"%@",[document description]);
if (document) {
    int numOfPages = CGPDFDocumentGetNumberOfPages(document);
    // NSLog(@"%d",numOfPages);
    CGPDFPageRef myPage = CGPDFDocumentGetPage(document, pgno);
    myContentStream = CGPDFContentStreamCreateWithPage(myPage);
    // CGPDFOperatorTableRef myTable;
    // myScanner = CGPDFScannerCreate (myContentStream, myTable, NULL);
    // CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
    // page = CGPDFDocumentGetPage(document, 2);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSaveGState(ctx);
    CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextConcatCTM(ctx,
                       CGPDFPageGetDrawingTransform(myPage, kCGPDFCropBox, [self bounds], 0, true));
    CGContextDrawPDFPage(ctx, myPage);
    CGContextRestoreGState(ctx);
}

}

最初我认为如果我将“pathForResources:ofType”方法参数更改为 svg,它会起作用但它不起作用,任何人都可以建议我修改。 谢谢你

【问题讨论】:

  • SVG 是一种与 PDF 完全不同的文件格式。您为什么希望 CGPDFDocument 能够处理它?
  • 刚刚检查了谢谢大家!!!!
  • 我知道这是一个老问题,但你可能想看看SVGKit。

标签: iphone objective-c ipad quartz-2d


【解决方案1】:

根据问题的 cmets:

【讨论】:

    【解决方案2】:

    结帐

    SVGKit SVGKit 是一个用于原生渲染 SVG 文件的 Cocoa 框架: 它快速而强大。 https://github.com/SVGKit/SVGKit#readme

    【讨论】:

      猜你喜欢
      • 2011-10-01
      • 1970-01-01
      • 2013-01-29
      • 2011-05-07
      • 2011-01-20
      • 2011-11-04
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      相关资源
      最近更新 更多