/// <summary> /// Creates a new pix instance using an existing handle to a pix structure. /// </summary> /// <remarks> /// Note that the resulting instance takes ownership of the data structure. /// </remarks> /// <param name="handle"></param> private Pix(IntPtr handle) { if (handle == IntPtr.Zero) throw new ArgumentNullException("handle"); this.handle = handle; this.width = Interop.LeptonicaApi.pixGetWidth(handle); this.height = Interop.LeptonicaApi.pixGetHeight(handle); this.depth = Interop.LeptonicaApi.pixGetDepth(handle); var colorMapHandle = Interop.LeptonicaApi.pixGetColormap(handle); if (colorMapHandle != IntPtr.Zero) { this.colormap = new PixColormap(colorMapHandle); } }
/// <summary> /// Creates a new pix instance using an existing handle to a pix structure. /// </summary> /// <remarks> /// Note that the resulting instance takes ownership of the data structure. /// </remarks> /// <param name="handle"></param> private Pix(IntPtr handle) { if (handle == IntPtr.Zero) { throw new ArgumentNullException("handle"); } this.handle = handle; this.width = Interop.LeptonicaApi.pixGetWidth(handle); this.height = Interop.LeptonicaApi.pixGetHeight(handle); this.depth = Interop.LeptonicaApi.pixGetDepth(handle); var colorMapHandle = Interop.LeptonicaApi.pixGetColormap(handle); if (colorMapHandle != IntPtr.Zero) { this.colormap = new PixColormap(colorMapHandle); } }
/// <summary> /// Creates a new pix instance using an existing handle to a pix structure. /// </summary> /// <remarks> /// Note that the resulting instance takes ownership of the data structure. /// </remarks> /// <param name="handle"></param> private Pix(IntPtr handle) { if (handle == IntPtr.Zero) { throw new ArgumentNullException(nameof(handle)); } this.Handle = new HandleRef(this, handle); this.Width = LeptonicaApi.Native.pixGetWidth(this.Handle); this.Height = LeptonicaApi.Native.pixGetHeight(this.Handle); this.Depth = LeptonicaApi.Native.pixGetDepth(this.Handle); var colorMapHandle = LeptonicaApi.Native.pixGetColormap(this.Handle); if (colorMapHandle != IntPtr.Zero) { this._colormap = new PixColormap(colorMapHandle); } }
/// <summary> /// Creates a new pix instance using an existing handle to a pix structure. /// </summary> /// <remarks> /// Note that the resulting instance takes ownership of the data structure. /// </remarks> /// <param name="handle"></param> private Pix(IntPtr handle) { if (handle == IntPtr.Zero) { throw new ArgumentNullException(nameof(handle)); } this.handle = new HandleRef(this, handle); this.width = Interop.LeptonicaApiSignatures.pixGetWidth(this.handle); this.height = Interop.LeptonicaApiSignatures.pixGetHeight(this.handle); this.depth = Interop.LeptonicaApiSignatures.pixGetDepth(this.handle); var colorMapHandle = Interop.LeptonicaApiSignatures.pixGetColormap(this.handle); if (colorMapHandle != IntPtr.Zero) { this.colormap = new PixColormap(colorMapHandle); } }
private void CopyColormap(Bitmap img, Pix pix) { var imgPalette = img.Palette; var imgPaletteEntries = imgPalette.Entries; var pixColormap = PixColormap.Create(pix.Depth); try { for (int i = 0; i < imgPaletteEntries.Length; i++) { if (!pixColormap.AddColor((PixColor)imgPaletteEntries[i])) { throw new InvalidOperationException(String.Format("Failed to add colormap entry {0}.", i)); } } pix.Colormap = pixColormap; } catch (Exception) { pixColormap.Dispose(); throw; } }