private ColorPalette _GetColorPalette() { int size = -1; int status = SafeNativeMethods.Gdip.GdipGetImagePaletteSize(new HandleRef(this, this.nativeImage), out size); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } ColorPalette palette = new ColorPalette(size); IntPtr ptr = Marshal.AllocHGlobal(size); status = SafeNativeMethods.Gdip.GdipGetImagePalette(new HandleRef(this, this.nativeImage), ptr, size); try { if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } palette.ConvertFromMemory(ptr); } finally { Marshal.FreeHGlobal(ptr); } return(palette); }
private ColorPalette _GetColorPalette() { int size = -1; int status = SafeNativeMethods.Gdip.GdipGetImagePaletteSize(new HandleRef(this, nativeImage), out size); // "size" is total byte size: // sizeof(ColorPalette) + (pal->Count-1)*sizeof(ARGB) if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } ColorPalette palette = new ColorPalette(size); // Memory layout is: // UINT Flags // UINT Count // ARGB Entries[size] IntPtr memory = Marshal.AllocHGlobal(size); status = SafeNativeMethods.Gdip.GdipGetImagePalette(new HandleRef(this, nativeImage), memory, size); try { if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } palette.ConvertFromMemory(memory); } finally { Marshal.FreeHGlobal(memory); } return(palette); }
internal ColorPalette retrieveGDIPalette() { int bytes; ColorPalette ret = new ColorPalette(); int st = Gdip.GdipGetImagePaletteSize(nativeImage, out bytes); Gdip.CheckStatus(st); IntPtr palette_data = Marshal.AllocHGlobal(bytes); try { st = Gdip.GdipGetImagePalette(nativeImage, palette_data, bytes); Gdip.CheckStatus(st); ret.ConvertFromMemory(palette_data); return ret; } finally { Marshal.FreeHGlobal(palette_data); } }
internal ColorPalette retrieveGDIPalette() { int bytes; ColorPalette ret = new ColorPalette(); Status st = SafeNativeMethods.Gdip.GdipGetImagePaletteSize(nativeObject, out bytes); SafeNativeMethods.Gdip.CheckStatus(st); IntPtr palette_data = Marshal.AllocHGlobal(bytes); try { st = SafeNativeMethods.Gdip.GdipGetImagePalette(nativeObject, palette_data, bytes); SafeNativeMethods.Gdip.CheckStatus(st); ret.ConvertFromMemory(palette_data); return(ret); } finally { Marshal.FreeHGlobal(palette_data); } }