Added processed image stuff
This commit is contained in:
parent
6d79d56ce3
commit
6b0856095d
|
|
@ -5,6 +5,8 @@ using System.Net.Http;
|
|||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace FrontEnd
|
||||
{
|
||||
|
|
@ -77,5 +79,31 @@ namespace FrontEnd
|
|||
}
|
||||
return clients;
|
||||
}
|
||||
|
||||
public static async Task<BitmapImage> GetProcessedCameraImage(Cam cam)
|
||||
{
|
||||
BitmapImage img = null;
|
||||
HttpResponseMessage response = await client.GetAsync($"cam/{cam.Id}/processed");
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
byte[] imgData = await response.Content.ReadAsByteArrayAsync();
|
||||
img = BytesToImage(imgData);
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
public static BitmapImage BytesToImage(byte[] array)
|
||||
{
|
||||
using (var ms = new System.IO.MemoryStream(array))
|
||||
{
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
image.Freeze();
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.Composition" />
|
||||
<Reference Include="System.Data" />
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace FrontEnd
|
|||
RenderTransform = new RotateTransform(cam.Angle),
|
||||
Width = 32,
|
||||
Height = 32,
|
||||
Tag = cam.Ip,
|
||||
Tag = cam,
|
||||
ToolTip = cam.Label
|
||||
};
|
||||
img.MouseDown += Cam_MouseDown;
|
||||
|
|
@ -47,7 +47,11 @@ namespace FrontEnd
|
|||
|
||||
private void Cam_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
new StreamWindow(((Image)sender).Tag.ToString()).ShowDialog();
|
||||
var cam = (Cam)((Image)sender).Tag;
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
new StreamWindow(cam, false).ShowDialog();
|
||||
else if (e.RightButton == MouseButtonState.Pressed)
|
||||
new StreamWindow(cam, true).ShowDialog();
|
||||
}
|
||||
|
||||
private void CreateClientMarker(Point pos, Client client)
|
||||
|
|
|
|||
|
|
@ -19,25 +19,38 @@ namespace FrontEnd
|
|||
/// </summary>
|
||||
public partial class StreamWindow : Window
|
||||
{
|
||||
private string _streamUri;
|
||||
private Cam _cam = null;
|
||||
private bool _processed;
|
||||
private StreamWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public StreamWindow(string streamUri) : this()
|
||||
|
||||
public StreamWindow(Cam cam, bool processed) : this()
|
||||
{
|
||||
_streamUri = streamUri;
|
||||
_cam = cam;
|
||||
_processed = processed;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_ = SimpleMJPEGDecoder.StartAsync((BitmapImage img) =>
|
||||
{
|
||||
imgStream.Dispatcher.Invoke(() => { imgStream.Source = img; });
|
||||
if (_processed)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
var img = await Communicator.GetProcessedCameraImage(_cam);
|
||||
_ = imgStream.Dispatcher.Invoke(() => { imgStream.Source = img; });
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = SimpleMJPEGDecoder.StartAsync((BitmapImage img) =>
|
||||
{
|
||||
imgStream.Dispatcher.Invoke(() => { imgStream.Source = img; });
|
||||
|
||||
},
|
||||
_streamUri);
|
||||
}, _cam.Ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" />
|
||||
<package id="System.IO" version="4.3.0" targetFramework="net472" />
|
||||
<package id="System.Net.Http" version="4.3.4" targetFramework="net472" />
|
||||
<package id="System.Net.Http.Formatting.Extension" version="5.2.3.0" targetFramework="net472" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue