如何将PNG图像读取到NSImage [英] How to read PNG image to NSImage

查看:106
本文介绍了如何将PNG图像读取到NSImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将PNG图像读取到NSImage。我尝试了以下方法,但是当我获得图像的宽度和大小时,我得到了一些怪异的值..如果有人可以将我引向正确的道路..非常合适..

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.");
 }

谢谢

推荐答案

您加载图像的代码正确。

Your code to load the image is correct.

显示尺寸的代码不正确; NSSize的成员是CGFloat,应使用%f格式字符串打印:

The code to display the size is incorrect; NSSize's members are CGFloat which should be print with the %f format string:

NSLog(@"size %f %f",picture.size.width, picture.size.height);

这篇关于如何将PNG图像读取到NSImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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