Ejemplo n.º 1
0
        public byte[] GetPicture(string devicePath, PictureSize pictureSize, Percent jpegCompressionRate)
        {
            var cacheKey = new PicturesCacheKey
            {
                DevicePath  = devicePath,
                PictureSize = pictureSize
            };

            if (!cacheValues.ContainsKey(cacheKey))
            {
                return(new byte[0]);
            }

            Console.WriteLine("GetPicture from cache");

            return(cacheValues[cacheKey].Data);
        }
Ejemplo n.º 2
0
        public bool HasPicture(string devicePath, PictureSize pictureSize, Percent jpegCompressionRate)
        {
            var cacheKey = new PicturesCacheKey
            {
                DevicePath = devicePath, PictureSize = pictureSize
            };

            if (!cacheValues.ContainsKey(cacheKey))
            {
                Console.WriteLine("ContainsKey {0}", false);
                return(false);
            }

            var value = cacheValues[cacheKey];

            return(!IsExpired(value));
        }
Ejemplo n.º 3
0
        public byte[] GetVideoFrame(Percent compressionRate = default(Percent))
        {
            if (!IsVideoStreamOpenned)
            {
                return(new byte[0]);
            }

            if (!CanReadVideoFrame)
            {
                Thread.Sleep(RemainingWaitingMilliseconds);
            }

            var pictureBuffer = RaspberryCamInterop.ReadVideoFrame(videoStreamHandle, (uint)(100 - compressionRate.Value));

            var data = new byte[pictureBuffer.Size];

            Marshal.Copy(pictureBuffer.Data, data, 0, pictureBuffer.Size);

            return(data);
        }
Ejemplo n.º 4
0
        public void AddPicture(string devicePath, PictureSize pictureSize, Percent jpegCompressionRate, byte[] data)
        {
            var cacheKey = new PicturesCacheKey
            {
                DevicePath  = devicePath,
                PictureSize = pictureSize
            };
            var cacheValue = new PicturesCacheValue
            {
                Time = DateTime.UtcNow,
                Data = data
            };

            if (!cacheValues.ContainsKey(cacheKey))
            {
                cacheValues.Add(cacheKey, cacheValue);
                return;
            }

            cacheValues[cacheKey] = cacheValue;
        }
Ejemplo n.º 5
0
        public void SavePicture(PictureSize pictureSize, string filename, Percent jpegCompressionRate = default(Percent))
        {
            var data = TakePicture(pictureSize, jpegCompressionRate);

            File.WriteAllBytes(filename, data);
        }
Ejemplo n.º 6
0
 public bool Equals(Percent other)
 {
     return(value == other.value);
 }