c# - Convert jbyte* to array<Byte>^ -


my c# code

using system; using system.collections.generic; using system.linq; using system.text; using sourceafis.simple; using system.windows.media.imaging;   namespace tempsample {     public class templetextractorsample     {         // inherit fingerprint in order add filename field         [serializable]         class myfingerprint : fingerprint         {             public string filename;         }          // inherit person in order add name field         [serializable]         class myperson : person         {             public string name;         }           static afisengine afis;          // take fingerprint image file , create person object image         public static string gettemplate(byte[] bytearray, string name)         {             console.writeline("enrolling {0}...", name);              // initialize empty fingerprint object , set properties             myfingerprint fp = new myfingerprint();             //bitmapimage image = new bitmapimage(new uri(filename, urikind.relativeorabsolute));               bitmapimage image = new bitmapimage();             image.begininit();             image.streamsource = new system.io.memorystream(bytearray);             image.endinit();              fp.asbitmapsource = image;             // above update of fp.asbitmapsource initialized raw image in fp.image             // check raw image dimensions, y axis first, x axis second             console.writeline(" image size = {0} x {1} (width x height)", fp.image.getlength(1), fp.image.getlength(0));               // initialize empty person object , set properties             myperson person = new myperson();             person.name = name;             // add fingerprint person             person.fingerprints.add(fp);              // execute extraction in order initialize fp.template             console.writeline(" extracting template...");             afis = new afisengine();             afis.extract(person);              // check template size             console.writeline(" template size = {0} bytes", fp.template.length);             byte[] b = fp.template;             string base64string = system.convert.tobase64string(b, 0, b.length);              return base64string;         }     } } 

vc++ code

#include "stdafx.h"  #include "templetgen.h"  #include "test5_templetgenerator.h"  #include <string> using system::text::encoding;  string^ tostring(const char *chars){     int len=(int)strlen(chars);     array<unsigned char>^ = gcnew array<unsigned char>(len);     int i=0;      while(i<len){         a[i] = chars[i];         i++;     }     return encoding::utf8->getstring(a);  }  string^ gettemplet(array<byte>^ byte,const char* p){      return tempsample::templetextractorsample::gettemplate(byte,tostring(p));  }   jniexport jstring jnicall java_test5_templetgenerator_gettemplate     (jnienv *env, jobject c, jbytearray imagearray, jstring name){          jbyte* bufferptr = env->getbytearrayelements(imagearray, null);         jboolean iscopyname;         const char *nm = env->getstringutfchars(name,&iscopyname);          return gettemplet(bufferptr, nm); } 

vc++ code showing compilation error in jni code

templetgen.cpp(39): error c2664: 'gettemplet' : cannot convert parameter 1 'jbyte *' 'cli::array ^'

please convert jni byte array (jbyte) array can c#function?

it appears have more 1 issue in code (i.e. gettemplet returns string^ attempt return jstring java_test5_templetgenerator_gettemplate method).

regarding specific question: how convert imagearray can used parameter 1 in call gettemplet method, can following:

int len = env->getarraylength(imagearray); unsigned char* bufferptr = reinterpret_cast<unsigned char*>(env->getbytearrayelements(imagearray, null)); array<byte>^ bytearray = gcnew array<byte>(len); marshal::copy((intptr)bufferptr, bytearray, 0, len); 

now can use bytearray parameter 1 in call gettemplet.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -