unsafe private void UpdateUnmanaged() { Debug.Assert(_palette != null && !_palette.IsInvalid); int numColors = Math.Min(256, _colors.Count); ImagePaletteColor[] paletteColorArray = new ImagePaletteColor[numColors]; for (int i = 0; i < numColors; ++i) { Color color = _colors[i]; paletteColorArray[i].B = color.B; paletteColorArray[i].G = color.G; paletteColorArray[i].R = color.R; paletteColorArray[i].A = color.A; } fixed(void *paletteColorArrayPinned = paletteColorArray) { HRESULT.Check(UnsafeNativeMethods.WICPalette.InitializeCustom( _palette, (IntPtr)paletteColorArrayPinned, numColors)); } }
private void UpdateManaged() { Debug.Assert(_palette != null && !_palette.IsInvalid); int numColors = 0; int cActualColors = 0; HRESULT.Check(UnsafeNativeMethods.WICPalette.GetColorCount(_palette, out numColors)); List <Color> colors = new List <Color>(); if (numColors < 1 || numColors > 256) { throw new InvalidOperationException(SR.Get(SRID.Image_PaletteZeroColors, null)); } else { ImagePaletteColor[] paletteColorArray = new ImagePaletteColor[numColors]; unsafe { fixed(void *paletteColorArrayPinned = paletteColorArray) { HRESULT.Check(UnsafeNativeMethods.WICPalette.GetColors( _palette, numColors, (IntPtr)paletteColorArrayPinned, out cActualColors)); Debug.Assert(cActualColors == numColors); } } for (int i = 0; i < numColors; ++i) { ImagePaletteColor c = paletteColorArray[i]; colors.Add(Color.FromArgb(c.A, c.R, c.G, c.B)); } } _colors = new PartialList <Color>(colors); }
private void UpdateManaged() { Debug.Assert(_palette != null && !_palette.IsInvalid); int numColors = 0; int cActualColors = 0; HRESULT.Check(UnsafeNativeMethods.WICPalette.GetColorCount(_palette, out numColors)); List<Color> colors = new List<Color>(); if (numColors < 1 || numColors > 256) { throw new InvalidOperationException(SR.Get(SRID.Image_PaletteZeroColors, null)); } else { ImagePaletteColor[] paletteColorArray = new ImagePaletteColor[numColors]; unsafe { fixed(void* paletteColorArrayPinned = paletteColorArray) { HRESULT.Check(UnsafeNativeMethods.WICPalette.GetColors( _palette, numColors, (IntPtr)paletteColorArrayPinned, out cActualColors)); Debug.Assert(cActualColors == numColors); } } for (int i = 0; i < numColors; ++i) { ImagePaletteColor c = paletteColorArray[i]; colors.Add(Color.FromArgb(c.A, c.R, c.G, c.B)); } } _colors = new PartialList<Color>(colors); }
unsafe private void UpdateUnmanaged() { Debug.Assert(_palette != null && !_palette.IsInvalid); int numColors = Math.Min(256, _colors.Count); ImagePaletteColor[] paletteColorArray = new ImagePaletteColor[numColors]; for (int i = 0; i < numColors; ++i) { Color color = _colors[i]; paletteColorArray[i].B = color.B; paletteColorArray[i].G = color.G; paletteColorArray[i].R = color.R; paletteColorArray[i].A = color.A; } fixed (void* paletteColorArrayPinned = paletteColorArray) { HRESULT.Check(UnsafeNativeMethods.WICPalette.InitializeCustom( _palette, (IntPtr)paletteColorArrayPinned, numColors)); } }