如何将PNG图像读取到NSImage
我如何将 PNG 图像读取到 NSImage。我尝试了以下方法,但是当我获得图像的宽度和大小时,我得到了一些奇怪的值..如果有人可以指导我走正确的道路..非常合适..
NSImage * picture = [[NSImage alloc] initWithContentsOfFile: [bundleRoot stringByAppendingString:tString]];
NSLog(@"sixe %d %d",picture.size.width, picture.size.height);
if( picture ){
NSLog(@"Picture is not null");
}else {
NSLog(@"Picture is null.");
}
谢谢
how can i read PNG image to NSImage. I tried the following way,but when i get the width and size of the image i'm getting some weird value.. if any one can direct me in right path.. highly appropriate..
NSImage * picture = [[NSImage alloc] initWithContentsOfFile: [bundleRoot stringByAppendingString:tString]];
NSLog(@"sixe %d %d",picture.size.width, picture.size.height);
if( picture ){
NSLog(@"Picture is not null");
}else {
NSLog(@"Picture is null.");
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您加载图像的代码是正确的。
显示尺寸的代码不正确; NSSize 的成员是 CGFloat,应使用 %f 格式字符串打印:
Your code to load the image is correct.
The code to display the size is incorrect; NSSize's members are CGFloat which should be print with the %f format string:
使用
[NSImage imageNamed:tString]
。 tString应该是图像文件的基本文件名;并且不需要包含文件扩展名。Use
[NSImage imageNamed:tString]
. tString should be the base file name of the image file; and need not contain a file extension.