internal void Save(Imaging.PixelFormat PixelFormat) { Bitmap SavedBitmap = new Bitmap(200, 200, PixelFormat); try { Imaging.ImageFormat Type = Imaging.ImageFormat.Bmp; if ((SaveFileDialog1.ShowDialog == Windows.Forms.DialogResult.OK) == false) { return; } switch (SaveFileDialog1.FilterIndex) { case 1: { Type = Imaging.ImageFormat.Bmp; break; } case 2: { Type = Imaging.ImageFormat.Gif; break; } case 3: { Type = Imaging.ImageFormat.Jpeg; break; } case 4: { Type = Imaging.ImageFormat.Tiff; break; } } DrawClock(SavedBitmap, frmOptions.chkShowHands.Checked); SavedBitmap.Save(SaveFileDialog1.FileName, Type); } catch (Exception ex) { if (MessageBox.Show(string.Format("Unhandled Error Has Occurred Please E-mail Me At {0} With The Following Message {1}{1}{2}{1}{1} Continue?", new[] { "*****@*****.**", Constants.vbCrLf, ex.ToString() }), "Unhandled Error", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2) == Windows.Forms.DialogResult.Yes) { return; } Application.ExitThread(); return; } finally { this.Timer1.Enabled = true; SavedBitmap.Dispose(); } Process.Start(SaveFileDialog1.FileName); SaveFileDialog1.FileName = ""; }
internal void Redraw(Imaging.PixelFormat PixelFormat) { if (ShownCompleted == true) { Bitmap = new Bitmap(200, 200, PixelFormat); } }
private static int GetBpp(Imaging.PixelFormat pixelFormat) { switch (pixelFormat) { case Imaging.PixelFormat.Indexed4: return(4); case Imaging.PixelFormat.Indexed8: return(8); default: throw new ArgumentException($"Pixel format {pixelFormat} not supported", nameof(pixelFormat)); } }
private static System.Windows.Media.PixelFormat GetPixelFormat(Imaging.PixelFormat pixelFormat) { switch (pixelFormat) { case Imaging.PixelFormat.Indexed4: return(PixelFormats.Indexed4); case Imaging.PixelFormat.Indexed8: return(PixelFormats.Indexed8); default: throw new ArgumentException($"Pixel format {pixelFormat} not supported", nameof(pixelFormat)); } }
private void ThreadProc() { Imaging.PixelFormat pixelFormat = PixelFormat.BGR_24bpp; switch (this.device.GetColorBpp()) { case 24: pixelFormat = PixelFormat.BGR_24bpp; break; case 32: pixelFormat = PixelFormat.BGRX_32bpp; break; default: throw new NotSupportedException("Expected 24bpp or 32bpp image."); } var colorImage = ImagePool.GetOrCreate((int)this.device.GetColorWidth(), (int)this.device.GetColorHeight(), pixelFormat); uint colorImageSize = this.device.GetColorHeight() * this.device.GetColorStride(); switch (this.device.GetDepthBpp()) { case 16: pixelFormat = PixelFormat.Gray_16bpp; break; case 8: pixelFormat = PixelFormat.Gray_8bpp; break; default: throw new NotSupportedException("Expected 8bpp or 16bpp image."); } var depthImage = DepthImagePool.GetOrCreate( (int)this.device.GetDepthWidth(), (int)this.device.GetDepthHeight(), DepthValueSemantics.DistanceToPlane, 0.001); uint depthImageSize = this.device.GetDepthHeight() * this.device.GetDepthStride(); while (!this.shutdown) { this.device.ReadFrame(colorImage.Resource.ImageData, colorImageSize, depthImage.Resource.ImageData, depthImageSize); DateTime t = DateTime.UtcNow; this.ColorImage.Post(colorImage, t); this.DepthImage.Post(depthImage, t); } }
private void EncodedImageVisualizationObject_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(this.EncodedImageVisualizationObject.CurrentValue)) { Imaging.Image psiImage = null; if (this.EncodedImageVisualizationObject.CurrentValue.HasValue) { var resource = this.EncodedImageVisualizationObject.CurrentValue.Value.Data.Resource; this.lastKnownImageWidth = resource.Width; this.lastKnownImageHeight = resource.Height; this.lastKnownPixelFormat = ImageDecoder.GetPixelFormat(resource); psiImage = new Imaging.Image(this.lastKnownImageWidth, this.lastKnownImageHeight, this.lastKnownPixelFormat); ImageDecoder.DecodeTo(resource, psiImage); } else { psiImage = new Imaging.Image(this.lastKnownImageWidth, this.lastKnownImageHeight, this.lastKnownPixelFormat); } if (this.EncodedImageVisualizationObject.Configuration.HorizontalFlip) { if (psiImage != null) { var bitmap = psiImage.ToManagedImage(true); bitmap.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX); // we dispose the new Shared object here because UpdateImage increments its ref count using (var sharedImage = Shared.Create(Imaging.Image.FromManagedImage(bitmap))) { this.DisplayImage.UpdateImage(sharedImage); } } else { this.DisplayImage.UpdateImage(null); } } else { // we dispose the new Shared object here because UpdateImage increments its ref count using (var sharedImage = Shared.Create(psiImage)) { this.DisplayImage.UpdateImage(sharedImage); } } } }
private void EncodedImageVisualizationObject_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(this.EncodedImageVisualizationObject.CurrentValue)) { Imaging.Image psiImage = null; if (this.EncodedImageVisualizationObject.CurrentValue.HasValue) { var resource = this.EncodedImageVisualizationObject.CurrentValue.Value.Data.Resource; this.lastKnownImageWidth = resource.Width; this.lastKnownImageHeight = resource.Height; this.lastKnownPixelFormat = resource.GetPixelFormat(); psiImage = new Imaging.Image(this.lastKnownImageWidth, this.lastKnownImageHeight, this.lastKnownPixelFormat); resource.DecodeTo(psiImage); } else { psiImage = new Imaging.Image(this.lastKnownImageWidth, this.lastKnownImageHeight, this.lastKnownPixelFormat); } if (this.EncodedImageVisualizationObject.Configuration.HorizontalFlip) { if (psiImage != null) { var bitmap = psiImage.ToManagedImage(true); bitmap.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX); this.DisplayImage.UpdateImage(Imaging.Image.FromManagedImage(bitmap)); } else { this.DisplayImage.UpdateImage((Imaging.Image)null); } } else { this.DisplayImage.UpdateImage(psiImage); } } }
/// <summary> /// Initializes a new instance of the <see cref="Mpeg4Writer"/> class. /// </summary> /// <param name="pipeline">Pipeline this component is a part of</param> /// <param name="filename">Name of output file to write to</param> /// <param name="width">Width of output image in pixels</param> /// <param name="height">Height of output image in pixels</param> /// <param name="pixelFormat">Format of input images</param> public Mpeg4Writer(Pipeline pipeline, string filename, uint width, uint height, Imaging.PixelFormat pixelFormat) : this(pipeline, filename) { this.configuration = Mpeg4WriterConfiguration.Default; this.configuration.ImageWidth = width; this.configuration.ImageHeight = height; this.configuration.PixelFormat = pixelFormat; }