将NSView保存到png文件? [英] Saving an NSView to a png file?

查看:127
本文介绍了将NSView保存到png文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的程序,该程序可以为我玩的游戏创建游戏卡.我已将其发送给我的一些朋友进行测试,但他们确实希望它保存图像,而不仅仅是打印图像.我试图使其另存为.png文件.我必须在这里提问.

I am making a simple program that creates game cards for a game I play. I have sent it out to some friends of mine for testing, but they really want it to save images, not just print them. I have tried to make it save as a .png file. I have to questions here.

  • 如何使其将视图保存为.png文件,包括视图的所有NSImageWells.

  • How can I make it save my view as a .png file, including all of the view's NSImageWells.

如何将NSPopupButton添加到NSSavePanel以允许用户选择格式?

How can I add an NSPopupButton to an NSSavePanel to allow users to select a format?

非常感谢您的帮助.

推荐答案

首先创建视图的TIFF表示形式:

First create a TIFF representation of your view:

// Get the data into a bitmap.
[self lockFocus];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self bounds]];
[self unlockFocus];
data = [rep TIFFRepresentation];

要支持多种文件类型,请使用:

To support multiple file types, use:

data = [rep representationUsingType:(NSBitmapImageFileType)storageType
properties:(NSDictionary *)properties];

NSBitmapImageFileType是一个枚举常量,用于指定位图图像的文件类型.可以是NSBMPFileType,NSGIFFileType,NSJPEGFileType,NSPNGFileType或NSTIFFFileType.

NSBitmapImageFileType is an enum constant specifying a file type for bitmap images. It can be NSBMPFileType, NSGIFFileType, NSJPEGFileType, NSPNGFileType, or NSTIFFFileType.

如果需要自定义NSSavePanel,请查看附件视图: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/AppFileMgmt/Articles/ManagingAccessoryViews.html

If you need to customize the NSSavePanel, look into accessory views: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/AppFileMgmt/Articles/ManagingAccessoryViews.html

这篇关于将NSView保存到png文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆