如何将本地jpeg或png图像文件加载到iPhone应用程序中? [英] How do you load a local jpeg or png image file into an iPhone app?

查看:108
本文介绍了如何将本地jpeg或png图像文件加载到iPhone应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

或者我应该问为什么对我这么难?答案可能是我是iPhone开发的新手,我正试图抛弃我的旧方法并进入未来的新平台。从开始到结束,我对这个过程有几个问题......

Or I should ask why is it so difficult for me? The answer is probably that I'm new to iPhone development and I'm trying to ditch my old methods and step into the new platform of the future. From start to finish, I have a few questions about this process...


  1. 如果我创建.png图像,它会去哪里在我项目的目录中(即我的电脑的硬盘)?我可以把它放在硬盘上的任何地方吗?当我把它加载到Xcode中时,Xcode会把它复制到正确的地方吗?

  2. 一旦它存在于我的硬盘上,我该如何添加它到我的Xcode项目?我可以将文件拖到Groups& Files树中的任何文件夹中吗?

  3. 将其拖入Xcode后,我想在该复制文件对话框中使用哪些复制设置弹出的盒子?将项目复制到目标组的文件夹复选框?参考类型?递归地为添加的文件夹创建组?

  4. 将.png图像正确添加到我的项目后,将它放入CGImageRef的最简单方法是什么?该文档显示了一个使用 CGImageCreateWithPNGDataProvider 辅助方法的示例,但表示iOS SDK不支持它。我想使用CGImageRef重复将图像绘制到位图上下文中。

  1. If I create a .png image, where does it go in my project's directory (i.e. my computer's hard drive)? Can I put it anywhere on my hard drive and Xcode will copy it in the right place when I load it into Xcode?
  2. Once it exists on my hard drive somewhere, how do I add it to my Xcode project? Can I just drag the file into any folder in the "Groups & Files" tree?
  3. Once I drag it into Xcode, what copy settings do I want to use in that copy file dialog box that pops up? Copy items into destination group's folder checkbox? Reference Type? Recursively create groups for added folders?
  4. Once the .png image has properly been added to my project, what's the easiest way to get it into an CGImageRef? The documentation shows an example using the CGImageCreateWithPNGDataProvider helper method, but says it's not supported by the iOS SDK. I'd like to use the CGImageRef for repeatedly drawing the image to a bitmap context.

非常感谢,我为此道歉这个冗长的问题,我感到惊讶的是,与其他平台相比,这是一个复杂的过程。

Thanks so much in advance and I apologize for the lengthy question, I'm just surprised it's such a convoluted process compared to some other platforms.

推荐答案

如果加载到UIImage ,你可以得到一个CGImageReg:

If you load into UIImage, you can get a CGImageReg:

    UIImage *image = [UIImage imageNamed:@"image.png"];
CGImageRef imageRef = [image CGImage];

这篇关于如何将本地jpeg或png图像文件加载到iPhone应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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