コード例 #1
0
        public async UniTask TakePhotoAsync(CameraMonitor capturedImage, CancellationToken ct)
        {
            var image = capturedImage.capturedImage;

            var(f, w, h) = (image.graphicsFormat, image.width, image.height);
            await UniTask.WaitForEndOfFrame(ct);

            var req = await AsyncGPUReadback.Request(image, 0).WithCancellation(ct);

            var rawByteArray = req.GetData <byte>();
            await UniTask.SwitchToThreadPool();

            using var jpg = ImageConversion.EncodeNativeArrayToJPG(rawByteArray, f, (uint)w, (uint)h);
            await UniTask.SwitchToMainThread(ct);

            var bytes = jpg.ToArray();

            photographyDataStore.Save("jpg", bytes);
        }
コード例 #2
0
ファイル: NativePayload.cs プロジェクト: natsuite/NatShare
        /// <summary>
        /// Add an image to the payload from a pixel buffer.
        /// The pixel buffer MUST have an RGBA8888 pixel layout.
        /// </summary>
        /// <param name="pixelBuffer">Pixel buffer containing image to add.</param>
        /// <param name="width">Image width.</param>
        /// <param name="height">Image height.</param>
        public virtual void AddImage <T> (T[] pixelBuffer, int width, int height) where T : unmanaged
        {
            // Check
            if (payload == IntPtr.Zero)
            {
                return;
            }
            // Compress
            using var nativeArray = new NativeArray <T>(pixelBuffer, Allocator.Temp);
            var buffer = ImageConversion.EncodeNativeArrayToJPG(
                nativeArray,
                GraphicsFormat.R8G8B8A8_UNorm,
                (uint)width,
                (uint)height,
                quality: 90
                ).ToArray();

            // Add
            payload.AddImage(buffer, buffer.Length);
        }