简体   繁体   English

从文档目录在Unity3d中为iPhone加载图像

[英]Load image from document directory for iphone in Unity3d

Hi i am working on unity 3d app, i have an url of image and i successfully download image from that url and store into document directory path and path is: /var/mobile/Applications/4EA2C956-FCA1-4552-AEE5-611A55B26CF5/Documents/sample.jpg, now i getting stuck into how to retreive image and show on as a texture i did following code. 嗨,我正在使用统一3D应用程序,我有一个图像的url,我成功地从该url下载了图像并将其存储到文档目录中,路径为:/ var / mobile / Applications / 4EA2C956-FCA1-4552-AEE5-611A55B26CF5 / Documents / sample.jpg,现在我陷入了如何获取图像并在代码中按照纹理进行显示的问题。

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);

I am getting confuse how to accomplish this task and also i want to do same videos like my path will be /var/mobile/Applications/4EA2C956-FCA1-4552-AEE5-611A55B26CF5/Documents/sampleVideo.mp4 . 我对如何完成此任务感到困惑,并且我也想做同样的视频,例如我的路径将是/var/mobile/Applications/4EA2C956-FCA1-4552-AEE5-611A55B26CF5/Documents/sampleVideo.mp4 I only want to do this task in unity 3d and in c sharp. 我只想在统一3d和c锐度中执行此任务。 This will be great for me. 这对我来说太好了。 Thanks in advance. 提前致谢。

I use this codes for load picture from documents directory, i guess you can make it with same codes 我使用此代码从文档目录中加载图片,我想您可以使用相同的代码进行加载

- (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];
}

call this method like this 像这样调用此方法

[ self loadImage: "your image name"];

You can use this code for getting the document directory path in C# script it might be helpful 您可以使用此代码在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";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM