예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
파일: Image.cs 프로젝트: radovanovic/corefx
        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);
            }
        }