123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
-
- namespace NRKernal.Record
- {
- using UnityEngine;
- using System.IO;
-
-
-
- public class NRCaptureBehaviour : CaptureBehaviourBase
- {
-
-
- private ImageEncoder ImageEncoder
- {
- get
- {
- return this.GetContext().GetEncoder() as ImageEncoder;
- }
- }
-
-
-
-
-
-
- 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, PhotoCaptureFileOutputFormat format, ref byte[] data)
- {
- data = this.ImageEncoder.Encode(width, height, format);
- if (data == null)
- {
- return false;
- }
- return true;
- }
-
-
-
-
- private void DoAsyn(CaptureTask task)
- {
- if (SystemInfo.supportsAsyncGPUReadback)
- {
- this.ImageEncoder.Commit(task);
- }
- else
- {
- var data = ImageEncoder.Encode(task.Width, task.Height, task.CaptureFormat);
- if (task.OnReceive != null)
- {
- task.OnReceive(task, data);
- }
- }
- }
-
-
-
-
- public void DoAsyn(NRPhotoCapture.OnCapturedToMemoryCallback oncapturedcallback)
- {
- var captureTask = new CaptureTask();
- var cameraParam = this.GetContext().RequestCameraParam();
- captureTask.Width = cameraParam.cameraResolutionWidth;
- captureTask.Height = cameraParam.cameraResolutionHeight;
- captureTask.CaptureFormat = cameraParam.pixelFormat == CapturePixelFormat.PNG ? PhotoCaptureFileOutputFormat.PNG : PhotoCaptureFileOutputFormat.JPG;
- captureTask.OnReceive += (task, data) =>
- {
- if (oncapturedcallback != null)
- {
- var result = new NRPhotoCapture.PhotoCaptureResult();
- result.resultType = NRPhotoCapture.CaptureResultType.Success;
- CapturePixelFormat format = task.CaptureFormat == PhotoCaptureFileOutputFormat.PNG ? CapturePixelFormat.PNG : CapturePixelFormat.JPEG;
- PhotoCaptureFrame frame = new PhotoCaptureFrame(format, data);
- oncapturedcallback(result, frame);
- }
- };
- this.DoAsyn(captureTask);
- }
-
-
-
- public void Do(string filename, PhotoCaptureFileOutputFormat fileOutputFormat)
- {
- var cameraParam = this.GetContext().RequestCameraParam();
- this.Do(cameraParam.cameraResolutionWidth,
- cameraParam.cameraResolutionHeight,
- fileOutputFormat,
- filename
- );
- }
- }
- }
|