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); }
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)); }
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); }
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; }
public void SavePicture(PictureSize pictureSize, string filename, Percent jpegCompressionRate = default(Percent)) { var data = TakePicture(pictureSize, jpegCompressionRate); File.WriteAllBytes(filename, data); }
public bool Equals(Percent other) { return(value == other.value); }