0

I tried with this code but it doesn't work.

`

#import <SVGKit/SVGKit.h>

//...

//create rect

NSRect r = NSMakeRect(100, 200, 500, 300);

SVGKImage* svgImage = [[SVGKImage alloc] init];

[svgImage setSize:r.size];

NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] 

initWithBitmapDataPlanes:NULL
                                                                       pixelsWide:r.size.width
                                                                   pixelsHigh:r.size.height
                                                                bitsPerSample:8
                                                              samplesPerPixel:4
                                                                     hasAlpha:YES
                                                                     isPlanar:NO
                                                               colorSpaceName:NSCalibratedRGBColorSpace
                                                                  bytesPerRow:0
                                                                 bitsPerPixel:0];


NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep:imageRep];

[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:context];
    
[svgImage.CALayerTree renderInContext:context.CGContext];

//draw content

NSData* svgData = [SVGKExporterNSData exportAsNSData:svgImage];

NSString* strFN = @"fileName.svg";

if ([svgData writeToFile:strFN atomically:YES])
    return true;

return false

`

Problem with this code is that svgImage.CALayerTree is null. Does anyone know how to use SVGKit to export NSView content in svg file?

kkemic
  • 59
  • 3

0 Answers0