Example #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);
        }
Example #2
0
        private void GetBitmapSource()
        {
            var handle = IntPtr.Zero;

            try
            {
                handle = GetHbitmap();
                Source = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty,
                                                               BitmapSizeOptions.FromEmptyOptions());
            }
            catch
            {
                // ignored
            }
            finally
            {
                if (handle != IntPtr.Zero)
                {
                    ExternDllHelper.DeleteObject(handle);
                }
            }
        }