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读取Ios中的动态UIImage图片
最新推荐文章于 2022-12-09 14:01:39 发布