iBee
July 4, 2013, 11:33am
1
Hello all,
I do not know how to return an image’s data from xcode
Normally, to get data something like “bool” function
extern “C” {
//Something like this
bool _IsThisOnXcode()
{
//return bool type of data
}
}
So, how do I call the function to get image data from xcode?
extern “C” {
??? _GetImage()
{
/return image data
//PNG data
}
}
Thank you!
iBee
July 4, 2013, 9:00pm
3
I could not get the const char* to return to C#
On Xcode:
const char* _GetImage(){
NSString *sString = @“Something”;
const char *cString = [sString UTF8String];
return cString;
}
On C#:
[DllImport (“__Internal”)]
private static extern string _GetImage();
public static string GetImage()
{
if (Application.platform != RuntimePlatform.OSXEditor)
{
return _GetImage();
} else {
return @“Hello”;
}
}
I always get this error: pointer being freed was not allocated
iBee
July 6, 2013, 9:15pm
5
You must return allocated pointer.
char* MakeStringCopy (const char* string) {
if (string == NULL)
return NULL;
char* res = (char*)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}
const char* _GetImage(){
NSString *sString = @“Something”;
const char *cString = [sString UTF8String];
return MakeStringCopy(cString);
}
Another way, Return an allocated Color32 array pointer. I did so on my plugin;). I never use UIImagePNGRepresentation.
Asset Store Link
https://www.assetstore.unity3d.com/#/content/9083
mcr
November 8, 2013, 9:11pm
10
Hi.
How do you go about returning a Color32 from Xcode? I’d like to be able to load all image thumbnails from iOS photo roll into Unity to display as Texture 2D in Unity.
Thanks!