2017-06-01 1 views
1

C#C# vuforia.image.pixels couvrent à iOS CIImage ou CGImage

private Vuforia.Image QCARoutput; 
QCARoutput = CameraDevice.Instance.GetCameraImage(Vuforia.Image.PIXEL_FORMAT.RGB888); 

_iOS_sendData(QCARoutput.Pixels, QCARoutput.Pixels.length); 

iOS

void _iOS_sendData(const char** ptrSrc, const int srcLength) { 

     NSData *imageData = [NSData dataWithBytes:(const void *)ptrSrc length:(sizeof(unsigned char) * srcLength)]; 
     CIImage *ciimg = [CIImage imageWithData:imageData]; 
     [delegateObject decodeWithQRcode:ciimg complete:^(NSString *result) { 
      NSLog(@"%@",result); 
     }]; 
} 

Je wannted pour obtenir Vuforia.image.pixels qui est l'octet [] . Puis envoyez à la couverture iOS à CIImage, mais ciimage est null. Comment puis-je couvrir ce byte [] à l'objet CIImage?

====== ====== Updata C#

[DllImport("__Internal")] 
private static extern void _iOS_sendData_ResultBlock(System.IntPtr ptrSrc, int srcLength); 

//================================================= 
QCARoutput = CameraDevice.Instance.GetCameraImage(Vuforia.Image.PIXEL_FORMAT.RGB888); 
IntPtr unmanagedPointer = Marshal.AllocHGlobal(QCARoutput.Pixels.Length); 
Marshal.Copy(QCARoutput.Pixels, 0, unmanagedPointer, QCARoutput.Pixels.Length); 
// Call unmanaged code 
Marshal.FreeHGlobal(unmanagedPointer); 
_iOS_sendData_ResultBlock(unmanagedPointer, QCARoutput.Pixels.Length); 

====== Updata Objective-C ======

void _iOS_sendData_ResultBlock(Byte *ptrSrc, const int srcLength, iOSUnityCallBack callback) { 

     NSData *imageData = [NSData dataWithBytes:ptrSrc length:(sizeof(unsigned char) * srcLength)]; 
     CIImage *ciimg = [CIImage imageWithData:imageData]; 
     if (ciimg == nil) { 
      NSLog(@"the ciimage is nil ,stop"); 
      return; 
     } 
} 

Je fais un changement. Ça ne marche pas.

Répondre

1

Je pense que vous devez modifier la déclaration de _iOS_sendData des deux côtés, C# et obj-c. Je devine que vous avez quelque chose comme ceci:

//c# side 
[DllImport ("__Internal")] 
private static extern void _iOS_sendData(byte[] bytes, int length); 

ne sais pas pourquoi, mais l'argument bytes doit être un pointeur de tableau, au lieu d'un véritable tableau. Je pense que c'est à cause de la façon dont Objective-C gère les choses.

les opérations suivantes:

//c# side 
[DllImport ("__Internal")] 
private static extern void _iOS_sendData(System.IntPtr bytes, int length); 

//obj-c side 
void _iOS_sendData(Byte * bytes, int length) 

source

+1

De plus, si OP veut modifier le tableau du côté natif, le tableau doit être épinglé en C# en premier afin que GC ne se déplace pas. Si ce n'est pas fait, il y aura des plantages aléatoires. – Programmer

+0

@Nika Kasradze J'ai écrit du code comme vous le dites, ça ne marche pas. Ai-je fait une erreur sur Byte * à NSData? Codes mis à jour. – ChokWah