private void ShowImage(object sender, RoutedEventArgs e) { Button b = sender as Button; MaterialInventoryDTO materialInventoryDTO = b.CommandParameter as MaterialInventoryDTO; MainWindow wnd = Application.Current.MainWindow as MainWindow; GetByteArrayResponse imageResponse = wnd.GetImage(materialInventoryDTO.ImageId); ImageWindow imageWindow = new ImageWindow(); imageWindow.Top = Application.Current.MainWindow.Top + 200; imageWindow.Left = Application.Current.MainWindow.Left + 200; if (imageResponse.ImageData != null && imageResponse.ImageData.Length > 0) { BitmapImage image = new BitmapImage(); using (var mem = new System.IO.MemoryStream(imageResponse.ImageData)) { mem.Position = 0; image.BeginInit(); image.CreateOptions = BitmapCreateOptions.PreservePixelFormat; image.CacheOption = BitmapCacheOption.OnLoad; image.StreamSource = mem; image.EndInit(); } image.Freeze(); imageWindow.ImageBox.Source = image; } imageWindow.Owner = wnd; imageWindow.ShowDialog(); }
public GetByteArrayResponse GetImage(long imageId) { GetByteArrayResponse response = new GetByteArrayResponse(); byte[] img = new byte[0]; try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:9000/"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream")); client.DefaultRequestHeaders.Add("EO-Header", User + " : " + Pwd); HttpResponseMessage httpResponse = client.GetAsync("api/Login/GetImage?imageId=" + ((long)imageId).ToString()).Result; if (httpResponse.IsSuccessStatusCode) { //string strData = httpResponse.Content.ReadAsStringAsync().Result; //response = JsonConvert.DeserializeObject<GetByteArrayResponse>(strData); img = httpResponse.Content.ReadAsByteArrayAsync().Result; response.ImageData = img; } else { MessageBox.Show("There was an error retreiving an image"); } } catch (Exception ex) { } return(response); }
public GetByteArrayResponse GetImage(long imageId) { GetByteArrayResponse response = new GetByteArrayResponse(); byte[] img = new byte[0]; try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(((App)App.Current).LAN_Address); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream")); client.DefaultRequestHeaders.Add("EO-Header", User + " : " + Pwd); HttpResponseMessage httpResponse = client.GetAsync("api/Login/GetImage?imageId=" + ((long)imageId).ToString()).Result; if (httpResponse.IsSuccessStatusCode) { //string strData = httpResponse.Content.ReadAsStringAsync().Result; //response = JsonConvert.DeserializeObject<GetByteArrayResponse>(strData); img = httpResponse.Content.ReadAsByteArrayAsync().Result; response.ImageData = img; } else { MessageBox.Show(Application.Current.MainWindow, "There was an error retreiving an image", "Error", MessageBoxButton.OK); } } catch (Exception ex) { Exception ex2 = new Exception("Admin - GetImage", ex); ((App)App.Current).LogError(ex2.Message, String.Empty); } return(response); }
public HttpResponseMessage GetImage([FromUri] long imageId) { GetByteArrayResponse response = new GetByteArrayResponse(); HttpResponseMessage httpResponse = new HttpResponseMessage(HttpStatusCode.ExpectationFailed); response.HttpResponse = httpResponse; try { byte[] imgData = inventoryManager.GetImage(imageId); httpResponse.Content = new ByteArrayContent(imgData); httpResponse.Content.Headers.ContentLength = imgData.Length; httpResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); httpResponse.StatusCode = HttpStatusCode.OK; } catch (Exception ex) { } return(httpResponse); }