コード例 #1
0
        internal static GifPropertyItem[] ConvertFromMemory(IntPtr propdata, int count)
        {
            var props = new GifPropertyItem[count];

            for (var i = 0; i < count; i++)
            {
                GifPropertyItemInternal propcopy = null;
                try
                {
                    propcopy = (GifPropertyItemInternal)ExternDllHelper.PtrToStructure(propdata,
                                                                                       typeof(GifPropertyItemInternal));

                    props[i] = new GifPropertyItem
                    {
                        Id    = propcopy.id,
                        Len   = propcopy.len,
                        Type  = propcopy.type,
                        Value = propcopy.Value
                    };

                    // this calls Marshal.Copy and creates a copy of the original memory into a byte array.

                    propcopy.value = IntPtr.Zero; // we dont actually own this memory so dont free it.
                }
                finally
                {
                    propcopy?.Dispose();
                }

                propdata = (IntPtr)((long)propdata + Marshal.SizeOf(typeof(GifPropertyItemInternal)));
            }

            return(props);
        }
コード例 #2
0
        internal GifPropertyItem GetPropertyItem(int propid)
        {
            GifPropertyItem propitem;

            var status = ExternDllHelper.Gdip.GdipGetPropertyItemSize(new HandleRef(this, NativeImage), propid, out var size);

            if (status != ExternDllHelper.Gdip.Ok)
            {
                throw ExternDllHelper.Gdip.StatusException(status);
            }

            if (size == 0)
            {
                return(null);
            }

            var propdata = Marshal.AllocHGlobal(size);

            if (propdata == IntPtr.Zero)
            {
                throw ExternDllHelper.Gdip.StatusException(ExternDllHelper.Gdip.OutOfMemory);
            }

            status = ExternDllHelper.Gdip.GdipGetPropertyItem(new HandleRef(this, NativeImage), propid, size, propdata);

            try
            {
                if (status != ExternDllHelper.Gdip.Ok)
                {
                    throw ExternDllHelper.Gdip.StatusException(status);
                }

                propitem = GifPropertyItemInternal.ConvertFromMemory(propdata, 1)[0];
            }
            finally
            {
                Marshal.FreeHGlobal(propdata);
            }

            return(propitem);
        }
コード例 #3
0
        internal static GifPropertyItemInternal ConvertFromPropertyItem(GifPropertyItem propItem)
        {
            var propItemInternal = new GifPropertyItemInternal
            {
                id   = propItem.Id,
                len  = 0,
                type = propItem.Type
            };

            var propItemValue = propItem.Value;

            if (propItemValue != null)
            {
                var length = propItemValue.Length;
                propItemInternal.len   = length;
                propItemInternal.value = Marshal.AllocHGlobal(length);
                Marshal.Copy(propItemValue, 0, propItemInternal.value, length);
            }

            return(propItemInternal);
        }