private static void UpdatePhoto(UIntPtr JPGPtr, UIntPtr width, UIntPtr height, UIntPtr size) { //Dispatch on main thread Dispatch.Dispatch(() => { if (JPGPtr == UIntPtr.Zero) { Ext.Warn("Failed to retrieve captured photo from device"); return; } Photo = #if ALLOCATE_NEW_PHOTO_TEXTURES new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false); #else Photo ?? new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false); if (Photo.width != (int)width || Photo.height != (int)height) //Realloc if size is different { MonoBehaviour.Destroy(Photo); Photo = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false); } #endif Photo.LoadRawTextureData(unchecked ((IntPtr)(long)(ulong)JPGPtr), (int)size); Photo.Apply(); ReleasePhotoBuffer(); PropagatePhoto(Photo); }); }
public static void CapturePhoto() { if (!supportedDevice) { Ext.Warn("Current device has no cameras"); return; } if (Preview == null) { return; } if (!Preview.isPlaying) { return; } #if ALLOCATE_NEW_PHOTO_TEXTURES Photo = new Texture2D(Preview.width, Preview.height); #else if (Photo == null) { Photo = new Texture2D(Preview.width, Preview.height); } #endif lock (bufferLock) { Preview.GetPixels32(PreviewBuffer); Photo.SetPixels32(PreviewBuffer); } Photo.Apply(); PropagatePhoto(Photo); }
public static void Play() { if (!supportedDevice) { Ext.Warn("Current device has no cameras"); return; } if (Preview == null) //First Play() { if (((Vector2)(DeviceCamera)mActiveCamera).x == 0) //Default { Preview = new WebCamTexture(WebCamTexture.devices[mActiveCamera].name); } else //Resolution set { Vector2 resolution = (Vector2)(DeviceCamera)mActiveCamera; float frameRate = (float)(DeviceCamera)mActiveCamera; if ((int)frameRate == 0) { Preview = new WebCamTexture(WebCamTexture.devices[mActiveCamera].name, (int)resolution.x, (int)resolution.y); } else { Preview = new WebCamTexture(WebCamTexture.devices[mActiveCamera].name, (int)resolution.x, (int)resolution.y, (int)frameRate); } } } Preview.Play(); }
public static void Pause() { if (!supportedDevice) { Ext.Warn("Current device has no cameras"); return; } Preview.Pause(); }
public static void SwitchActiveCamera() { if (!supportedDevice) { Ext.Warn("Current device has no cameras"); return; } FirstFrameReceived = false; Preview.Stop(); Preview.deviceName = WebCamTexture.devices[mActiveCamera].name; Preview.Play(); }
private static void UpdateCode(int format, IntPtr ptr, UIntPtr size) { //Get the string immediately since we can't guarantee memory preservation if (ptr == IntPtr.Zero) { Ext.Warn("Detected barcode string does not exist"); return; } string code = Marshal.PtrToStringUni(ptr, unchecked ((int)(uint)size)); if (code == null) { Ext.Warn("Detected barcode string is null"); return; } //Dispatch on main thread Dispatch.Dispatch(() => { PropagateBarcode(new Barcode(code, (BarcodeFormat)format)); }); }