public void Log_ValidPosition_SaveImageToFileWithPosition() { // Arrange var stream = new MemoryStream(); var fileSystemMock = new Mock<IFileSystem>(); fileSystemMock.Setup(fs => fs.OpenWrite(It.IsAny<string>())).Returns(stream); AlrpFileLogger target = new AlrpFileLogger(fileSystemMock.Object, ""); // Act var position = new Position() { Latitude = 1.0, Longitude = 2.0 }; var image = Image.FromFile("image_withgps.jpg"); target.Log(position, image); // Assert var actual = stream.ToArray(); File.WriteAllBytes("c:\\test.jpg", actual); }
private void AddGeotag(Image image, Position position) { byte[] latitude = BitConverter.GetBytes(position.Latitude); byte[] longitude = BitConverter.GetBytes(position.Longitude); WriteExifString(image, PropertyTagSoftwareUsed, "PI ALPR"); var lat = image.PropertyItems.Where(p => p.Id == PropertyTagGpsLatitude).Single(); //PropertyItem longitudeProperty = image.PropertyItems[0]; //longitudeProperty.Id = 0x0002; //longitudeProperty.Type = 5; //longitudeProperty.Len = longitude.Length; //longitudeProperty.Value = longitude; //image.SetPropertyItem(longitudeProperty); //PropertyItem latitudeProperty = image.PropertyItems[0]; //latitudeProperty.Id = 0x0004; //latitudeProperty.Type = 5; //longitudeProperty.Len = longitude.Length; //latitudeProperty.Value = latitude; //image.SetPropertyItem(latitudeProperty); }
public void Log(Position position, Image image) { this.CleanupOldFiles(); this.AddGeotag(image, position); string path = this.GetPath(position); // We can mock OpenWrite to return a MemoryStream using (var stream = this.fileSystem.OpenWrite(path)) { image.Save(stream, ImageFormat.Jpeg); } }
private string GetPath(Position position) { return ""; //throw new NotImplementedException(); }