1

カスタム ビューの drawRect ルーチンで通常提供される特定の CGContextRef に描画する void がありますが、結果の画像を PNG ファイルとして保存できるように描画できる CGContextRef も生成する必要があります。 .

4

1 に答える 1

4

それは非常に単純であることがわかりました:

NSImage *toSave = [[NSImage alloc] initWithSize:CGSizeMake(600, 900)];

[toSave lockFocus];

CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];

//drawing code

[toSave unlockFocus];

NSBitmapImageRep *imgRep = [[toSave representations] objectAtIndex: 0];

NSData *data = [imgRep representationUsingType: NSPNGFileType properties: nil];

[data writeToFile: @"/path/to/file.png" atomically: NO];
于 2012-05-30T18:20:27.663 に答える