您的位置:首页 > 移动开发 > Unity3D

Unity3D读取Ios中的动态UIImage图片

2013-03-08 16:47 399 查看
extern "C"
{
const char*  _GetImage()
{
NSLog(@"I am in Begin");
UIImage *myUIImage = [UIImage imageNamed:@"Test.jpg"];
NSData *imageData = UIImagePNGRepresentation(myUIImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Test.jpg"]; //Add the file name
NSLog(@"filePath %@",filePath);
[imageData writeToFile:filePath atomically:YES];
return MakeStringCopy([filePath UTF8String]);
}
}

[DllImport ("__Internal")]
private static extern String _GetImage();
public Texture2D texture2D;

void Start () {
texture2D = new Texture2D (200, 200);
imagePath = GetImage();
byte[] imageBytes = File.ReadAllBytes(imagePath);
texture2D.LoadImage(imageBytes);
}

void OnGUI () {
GUI.Button (new Rect(20,20,100,100),texture2D);
}

public static String GetImage()
{
if (Application.platform != RuntimePlatform.OSXEditor)
{
return _GetImage();
}
else
{
return @"Hello";
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3d