从Unity3D的iPhone文档目录加载图像
问题描述:
您好我正在团结3D应用程序,我有一个图像的URL,我成功地从该URL下载图像并存储到文档目录路径和路径是:/ var/mobile /应用程序/ 4EA2C956-FCA1-4552-AEE5-611A55B26CF5/Documents/sample.jpg,现在我陷入了如何检索图像并显示为纹理,我做了以下代码。从Unity3D的iPhone文档目录加载图像
WWW imageToLoadPath = new WWW(/var/mobile/Applications/4EA2C956-FCA1-4552-AEE5-611A55B26CF5/Documents/sample.jpg)
//rendering texture
imageToLoadPath.LoadImageIntoTexture(mIconPlane.renderer.material.mainTexture as Texture2D);
我越来越混淆如何完成此任务,也是我想要做的像我一样的路径影片将在/ var /移动/应用/ 4EA2C956-FCA1-4552-AEE5-611A55B26CF5 /文档/ sampleVideo .mp4。 我只想在统一3D和c sharp中做这个任务。 这对我来说很棒。提前致谢。
答
我用这个代码从文件目录加载图片,我想你可以使用相同的代码,使其
- (UIImage*)loadImage:(NSString*)imageName {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]];
UIImage *graphImage = [[UIImage alloc] initWithContentsOfFile: fullPath];
img1.image = graphImage;
return [UIImage imageWithContentsOfFile:fullPath];
}
调用此方法像这样
[ self loadImage: "your image name"];
+3
我想要统一3D和C锐利。 – josh
答
您可以使用此代码获取C#脚本中的文档目录路径可能有帮助
public static string GetiPhoneDocumentsPath()
{
// Application.dataPath returns
// /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data
// Strip "/Data" from path
string path = Application.dataPath.Substring (0, Application.dataPath.Length - 5);
// Strip application name
path = path.Substring(0, path.LastIndexOf('/'));
return path + "/Documents";
}
阅读文档Apple have prov ided关于访问您的应用程序沙箱中的文件,包括文档目录! –
我只想在统一3D和c sharp中做这个任务。 – josh
认真我做研究和谷歌搜索,也发布在统一答案论坛这里是链接“http://answers.unity3d.com/questions/358268/load-image-from-document-directory-for-iphone.html”,但我仍然无法得到任何帮助。 – josh