TakePhoto.cs IEnumerator Start () {//Get the camera yield returnapplication.requestuserauthorization (Userauthorization.webcam); if(Application.hasuserauthorization (Userauthorization.webcam)) {webcamdevice[] devices=webcamtexture.devices; if(Devices! =NULL) {
//Get device name devicename= devices[0].name; Tex=NewWebcamtexture (DeviceName, -, -, A); Tex. Play (); } } } //Get Pixel Private byte[] Getphotopixel (Webcamtexture CA) {texture2d texture=Newtexture2d (ca.width,ca.height); inty =0; while(Y <texture.height) {intx =0; while(X <texture.width) {unityengine.color Color=ca. GetPixel (x, y); Texture. SetPixel (X,y,color); ++x; } ++y; } texture. Apply ();//texture.name = name; byte[] Pngdata =getjpgdata (texture); returnPngdata; } //Control Photo Size Private byte[] Getjpgdata (Texture2d te) {byte[] Data=NULL ; intQuelity = the ; while(Quelity > -) {Data=te. Encodetojpg (quelity); intsize = data. length/1024x768; if(Size > -) {quelity-=5; } Else { Break ; } } returndata; }
Unity3d using a C # script to call an external camera to take a photo and convert it into a byte array