/// <summary> Constructor. </summary> /// <param name="w"> The width.</param> /// <param name="h"> The height.</param> /// <param name="format"> Describes the format to use.</param> /// <param name="callback"> The callback.</param> public CaptureTask(int w, int h, PhotoCaptureFileOutputFormat format, CaptureTaskCallback callback) { this.Width = w; this.Height = h; this.CaptureFormat = format; this.OnReceive = callback; }
//----------------------------------------------------------------- public void TakePhotoAsync(string filename, PhotoCaptureFileOutputFormat fileOutputFormat, OnCapturedToDiskCallback onCapturedPhotoToDiskCallback) { if (onCapturedPhotoToDiskCallback == null) { throw new ArgumentNullException("onCapturedPhotoToDiskCallback"); } if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("filename"); } // Make sure we don't have any forward slashes. // WinRT Apis do not like forward slashes. filename = filename.Replace("/", @"\"); string directory = System.IO.Path.GetDirectoryName(filename); if (!string.IsNullOrEmpty(directory) && !System.IO.Directory.Exists(directory)) { throw new ArgumentException("The specified directory does not exist.", "filename"); } System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename); if (fileInfo.Exists && fileInfo.IsReadOnly) { throw new ArgumentException("Cannot write to the file because it is read-only.", "filename"); } CapturePhotoToDisk_Internal(filename, fileOutputFormat, onCapturedPhotoToDiskCallback); }
public void TakePhotoAsync(string filename, PhotoCaptureFileOutputFormat fileOutputFormat, PhotoCapture.OnCapturedToDiskCallback onCapturedPhotoToDiskCallback) { if (this.m_NativePtr == IntPtr.Zero) { throw new InvalidOperationException("You must create a Photo Capture Object before taking a photo."); } if (onCapturedPhotoToDiskCallback == null) { throw new ArgumentNullException("onCapturedPhotoToDiskCallback"); } if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("filename"); } filename = filename.Replace("/", "\\"); string directoryName = Path.GetDirectoryName(filename); if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName)) { throw new ArgumentException("The specified directory does not exist.", "filename"); } FileInfo fileInfo = new FileInfo(filename); if (fileInfo.Exists && fileInfo.IsReadOnly) { throw new ArgumentException("Cannot write to the file because it is read-only.", "filename"); } this.CapturePhotoToDisk_Internal(this.m_NativePtr, filename, (int)fileOutputFormat, onCapturedPhotoToDiskCallback); }
public void TakePhotoAsync(string filename, PhotoCaptureFileOutputFormat fileOutputFormat, PhotoCapture.OnCapturedToDiskCallback onCapturedPhotoToDiskCallback) { bool flag = onCapturedPhotoToDiskCallback == null; if (flag) { throw new ArgumentNullException("onCapturedPhotoToDiskCallback"); } bool flag2 = string.IsNullOrEmpty(filename); if (flag2) { throw new ArgumentNullException("filename"); } filename = filename.Replace("/", "\\"); string directoryName = Path.GetDirectoryName(filename); bool flag3 = !string.IsNullOrEmpty(directoryName) && !System.IO.Directory.Exists(directoryName); if (flag3) { throw new ArgumentException("The specified directory does not exist.", "filename"); } FileInfo fileInfo = new FileInfo(filename); bool flag4 = fileInfo.Exists && fileInfo.IsReadOnly; if (flag4) { throw new ArgumentException("Cannot write to the file because it is read-only.", "filename"); } this.CapturePhotoToDisk_Internal(filename, fileOutputFormat, onCapturedPhotoToDiskCallback); }
public bool Do(int width, int height, BlendMode blendmode, PhotoCaptureFileOutputFormat format, ref byte[] data) { data = this.Do(width, height, blendmode, format); if (data == null) { return(false); } return(true); }
/// <summary> Does the given file. </summary> /// <param name="width"> The width.</param> /// <param name="height"> The height.</param> /// <param name="format"> Describes the format to use.</param> /// <param name="data"> [in,out] The data.</param> /// <returns> True if it succeeds, false if it fails. </returns> public bool Do(int width, int height, PhotoCaptureFileOutputFormat format, ref byte[] data) { data = this.ImageEncoder.Encode(width, height, format); if (data == null) { return(false); } return(true); }
/// <summary> Does the given file. </summary> /// <param name="filename"> Filename of the file.</param> /// <param name="fileOutputFormat"> The file output format.</param> public void Do(string filename, PhotoCaptureFileOutputFormat fileOutputFormat) { var cameraParam = this.GetContext().RequestCameraParam(); this.Do(cameraParam.cameraResolutionWidth, cameraParam.cameraResolutionHeight, fileOutputFormat, filename ); }
/// <summary> Does the given file. </summary> /// <param name="width"> The width.</param> /// <param name="height"> The height.</param> /// <param name="format"> Describes the format to use.</param> /// <param name="outpath"> The outpath.</param> /// <returns> True if it succeeds, false if it fails. </returns> public bool Do(int width, int height, PhotoCaptureFileOutputFormat format, string outpath) { var data = this.ImageEncoder.Encode(width, height, format); if (data == null) { return(false); } File.WriteAllBytes(outpath, data); return(true); }
public bool Do(int width, int height, BlendMode blendmode, PhotoCaptureFileOutputFormat format, string outpath) { var data = this.Do(width, height, blendmode, format); if (data == null) { return(false); } File.WriteAllBytes(outpath, data); return(true); }
public void TakePhotoAsync(string filename, PhotoCaptureFileOutputFormat fileOutputFormat, OnCapturedToDiskCallback onCapturedPhotoToDiskCallback) { try { var capture = m_CaptureContext.GetBehaviour(); ((NRCaptureBehaviour)capture).Do(filename, fileOutputFormat); } catch (Exception) { throw; } }
public byte[] Encode(int width, int height, PhotoCaptureFileOutputFormat format) { if (m_CurrentFrame == null) { NRDebugger.LogWarning("Current frame is empty!"); return(null); } byte[] data = null; RenderTexture pre = RenderTexture.active; RenderTexture targetRT = m_CurrentFrame; RenderTexture.active = targetRT; Texture2D texture2D = new Texture2D(targetRT.width, targetRT.height, TextureFormat.ARGB32, false); texture2D.ReadPixels(new Rect(0, 0, targetRT.width, targetRT.height), 0, 0); texture2D.Apply(); RenderTexture.active = pre; Texture2D outPutTex = texture2D; Texture2D scaleTexture = null; // Scale the texture while the output width or height not equal to the targetRT. if (width != targetRT.width || height != targetRT.height) { scaleTexture = ImageEncoder.ScaleTexture(texture2D, width, height); outPutTex = scaleTexture; } switch (format) { case PhotoCaptureFileOutputFormat.JPG: data = outPutTex.EncodeToJPG(); break; case PhotoCaptureFileOutputFormat.PNG: data = outPutTex.EncodeToPNG(); break; default: break; } // Clear the temp texture. GameObject.Destroy(texture2D); if (scaleTexture != null) { GameObject.Destroy(scaleTexture); } return(data); }
public void Do(string filename, PhotoCaptureFileOutputFormat fileOutputFormat) { if (!m_IsInit) { return; } this.Do(m_CameraParameters.cameraResolutionWidth, m_CameraParameters.cameraResolutionHeight, m_CameraParameters.blendMode, fileOutputFormat, filename ); }
public void TakePhotoAsync(string filename, PhotoCaptureFileOutputFormat fileOutputFormat, OnCapturedToDiskCallback onCapturedPhotoToDiskCallback) { if (this.m_NativePtr == IntPtr.Zero) { throw new InvalidOperationException("You must create a Photo Capture Object before taking a photo."); } if (onCapturedPhotoToDiskCallback == null) { throw new ArgumentNullException("onCapturedPhotoToDiskCallback"); } if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("filename"); } filename = filename.Replace("/", @"\"); string directoryName = Path.GetDirectoryName(filename); if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName)) { throw new ArgumentException("The specified directory does not exist.", "filename"); } this.CapturePhotoToDisk_Internal(this.m_NativePtr, filename, (int) fileOutputFormat, onCapturedPhotoToDiskCallback); }
private byte[] Do(int width, int height, BlendMode blendmode, PhotoCaptureFileOutputFormat format) { if (!m_IsInit) { return(null); } byte[] data = null; RenderTexture pre = RenderTexture.active; RenderTexture targetRT; switch (blendmode) { case BlendMode.RGBOnly: targetRT = m_CameraInput.RGBTexture; break; case BlendMode.VirtualOnly: targetRT = m_CameraInput.VirtualTexture; break; case BlendMode.Blend: targetRT = m_CameraInput.BlendTexture; break; case BlendMode.WidescreenBlend: Debug.LogError("Do not support WidescreenBlend mode."); return(null); default: return(null); } RenderTexture.active = targetRT; Texture2D texture2D = new Texture2D(targetRT.width, targetRT.height, TextureFormat.ARGB32, false); texture2D.ReadPixels(new Rect(0, 0, targetRT.width, targetRT.height), 0, 0); texture2D.Apply(); RenderTexture.active = pre; Texture2D outPutTex = texture2D; Texture2D scaleTexture = null; // Scale the texture while the output width or height not equal to the targetRT. if (width != targetRT.width || height != targetRT.height) { scaleTexture = ImageEncoder.ScaleTexture(texture2D, width, height); outPutTex = scaleTexture; } switch (format) { case PhotoCaptureFileOutputFormat.JPG: data = outPutTex.EncodeToJPG(); break; case PhotoCaptureFileOutputFormat.PNG: data = outPutTex.EncodeToPNG(); break; default: break; } // Clear the temp texture. Destroy(texture2D); if (scaleTexture != null) { Destroy(scaleTexture); } return(data); }
private extern void CapturePhotoToDisk_Internal(string filename, PhotoCaptureFileOutputFormat fileOutputFormat, OnCapturedToDiskCallback onCapturedPhotoToDiskCallback);
public void TakePhotoAsync(string filename, PhotoCaptureFileOutputFormat fileOutputFormat, OnCapturedToDiskCallback onCapturedPhotoToDiskCallback) { CaptureBehaviour.Do(filename, fileOutputFormat); }