private void OnBaseImageSelected(BaseImageSelected message) { TileResolutions = CreateTileResolutions(); ImageResolutions = CreateImageResolutions(message); SelectedTileResolution = TileResolutions.First(); SelectedImageResolution = ImageResolutions.First(); }
/// <summary> /// Captures a compressed video frame from the camera. /// This method will try querying the image for a number of times until a valid image is received /// or all the queries time out. /// </summary> /// <returns>A Bitmap.</returns> /// <exception cref="TimeoutException">Thrown if the capture image query times out for every try.</exception> public Bitmap ForceCaptureImage() { int minResponseTimeout = Math.Max(this.ResponseTimeout, this._currentImageResolution.Timeout / 2); int maxResponseTimeout = Math.Max(this._currentImageResolution.Timeout, minResponseTimeout); int numTries = 5;// should be > 1; int increaseTimeout = (maxResponseTimeout - minResponseTimeout) / (numTries - 1); this.ResponseTimeout = minResponseTimeout; Bitmap frame = null; for (int i = 0; i < numTries; i++) { try { frame = this.CaptureImage(); break; } catch (TimeoutException) { this.ResponseTimeout += increaseTimeout; } } // Revert ResponseTimeout to the default value. this.ResponseTimeout = _responseTimeout; if (frame == null) { throw new TimeoutException("Image capture timed out for " + numTries + " tries."); } // Set current image resolution from the captured image. ImageResolutions res = this._currentImageResolution.Resolution; switch (frame.Width) { case 80: res = ImageResolutions.Resolution80x64; break; case 160: res = ImageResolutions.Resolution160x128; break; case 320: res = ImageResolutions.Resolution320x240; break; } if (this._currentImageResolution.Resolution != res) { this._currentImageResolution = new ImageResolution(res); } return(frame); }
public ImageCanvas() { layers = new List <Layer>(); this.Background = Brushes.Transparent; dataController = new ImageDataManagementController(50); OpenfileName = ""; openfileRes = ImageResolutions.Undefined; this.LayerNum = 1; lastChangeSaved = true; Focusable = true; Cursor = ImageCanvas.penCursor; }
public static ImageFormat SaveListResolutions(string base64) { if (string.IsNullOrEmpty(base64)) { return(null); } try { var jpegArray = new ImageResolutions().GetType().GetProperties() .Where(x => Attribute.IsDefined(x, typeof(ImageResolutionAttribute))); var webpArray = new ImageResolutions().GetType().GetProperties() .Where(x => Attribute.IsDefined(x, typeof(ImageResolutionAttribute))); var resultImageList = new List <ResultImage>(); foreach (var item in jpegArray) { resultImageList.Add(GetImageConverted(base64, item.GetCustomAttribute <ImageResolutionAttribute>().Size)); } if (resultImageList == null) { return(null); } var instanceJpeg = Activator.CreateInstance(typeof(ImageResolutions)); var instanceWebp = Activator.CreateInstance(typeof(ImageResolutions)); foreach (var item in jpegArray) { item.SetValue(instanceJpeg, resultImageList.Find(x => x.Size == item.GetCustomAttribute <ImageResolutionAttribute>().Size).ImageJpeg); } foreach (var item in webpArray) { item.SetValue(instanceWebp, resultImageList.Find(x => x.Size == item.GetCustomAttribute <ImageResolutionAttribute>().Size).ImageWebp); } return(new ImageFormat { Jpeg = (ImageResolutions)instanceJpeg, Webp = (ImageResolutions)instanceWebp }); } catch (Exception e) { return(null); } }
/// <summary> /// Sets the camera capture resolution. /// </summary> /// <param name="resolution">A predefined image resolution to use when capturing images from the camera.</param> /// <exception cref="ArgumentException">Thrown if ImageResolution is set to a value other than one of the predefined resolutions.</exception> public void SetImageResolution(ImageResolutions resolution) { switch (resolution) { case ImageResolutions.Resolution80x64: this.SendCommand(SerialCommands.SetCaptureResolutionTo_80x64); break; case ImageResolutions.Resolution160x128: this.SendCommand(SerialCommands.SetCaptureResolutionTo_160x128); break; case ImageResolutions.Resolution320x240: this.SendCommand(SerialCommands.SetCaptureResolutionTo_320x240); break; default: throw new ArgumentException("Invalid resolution"); } this._currentImageResolution = new ImageResolution(resolution); }
public static bool SaveImageRender(FrameworkElement visual, string path, ImageResolutions res) { try { var bmp = new RenderTargetBitmap((int)visual.ActualWidth, (int)visual.ActualHeight, 96, 96, PixelFormats.Default); bmp.Render(visual); BitmapEncoder encoder; switch (res) { case ImageResolutions.BMP: encoder = new BmpBitmapEncoder(); break; case ImageResolutions.GIF: encoder = new GifBitmapEncoder(); break; case ImageResolutions.JPG: encoder = new JpegBitmapEncoder(); break; case ImageResolutions.PNG: encoder = new PngBitmapEncoder(); break; case ImageResolutions.TIF: encoder = new TiffBitmapEncoder(); break; case ImageResolutions.WDP: encoder = new WmpBitmapEncoder(); break; default: encoder = new JpegBitmapEncoder(); break; } encoder.Frames.Add(BitmapFrame.Create(bmp)); using (var img = File.Create(path)) encoder.Save(img); return(true); } catch (Exception excp) { MessageBox.Show(excp.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
public ImageResolution(ImageResolutions resolution) : this(resolution, 0, 0) { switch (resolution) { case ImageResolutions.Resolution80x64: this.Set(80, 64); break; case ImageResolutions.Resolution160x128: this.Set(160, 128); break; case ImageResolutions.Resolution320x240: this.Set(320, 240); break; } }
private ImageResolution(ImageResolutions resolution, int width, int height) { this._resolution = resolution; this._width = width; this._height = height; }