Ejemplo n.º 1
0
        public void ImageList_ImageStream_SetStreamerSerializedDisposed_Nop(ColorDepth colorDepth)
        {
            using var sourceList = new ImageList
                  {
                      ColorDepth = colorDepth,
                      ImageSize  = new Size(32, 32)
                  };
            var image = new Bitmap(10, 10);

            sourceList.Images.Add(image);
            ImageListStreamer stream = RoundtripSerialize(sourceList.ImageStream);

            Assert.True(sourceList.HandleCreated);
            stream.Dispose();
            Assert.True(sourceList.HandleCreated);

            using var list = new ImageList
                  {
                      ImageStream = stream
                  };
            Assert.Equal(ColorDepth.Depth8Bit, list.ColorDepth);
            Assert.Empty(list.Images);
            Assert.Equal(new Size(16, 16), list.ImageSize);
            Assert.False(list.HandleCreated);
            Assert.True(sourceList.HandleCreated);
        }
        public void ImageListStreamer_RoundTripAndExchangeWithNet()
        {
            string netBlob;

            using (var imageList = new ImageList()
            {
                ImageSize = new Size(16, 16),
                TransparentColor = Color.White
            })
            {
                imageList.Images.Add(new Bitmap(16, 16));
                netBlob = BinarySerialization.ToBase64String(imageList.ImageStream);
            }

            // ensure we can deserialise NET serialised data and continue to match the payload
            ValidateResult(netBlob);
            // ensure we can deserialise NET Fx serialised data and continue to match the payload
            ValidateResult(ClassicImageListStreamer);

            void ValidateResult(string blob)
            {
                using ImageListStreamer result = BinarySerialization.EnsureDeserialize <ImageListStreamer>(blob);
                using (NativeImageList nativeImageList = result.GetNativeImageList())
                {
                    Assert.True(ComCtl32.ImageList.GetIconSize(new HandleRef(this, nativeImageList.Handle), out int x, out int y).IsTrue());
                    Assert.Equal(16, x);
                    Assert.Equal(16, y);
                    var imageInfo = new ComCtl32.IMAGEINFO();
                    Assert.True(ComCtl32.ImageList.GetImageInfo(new HandleRef(this, nativeImageList.Handle), 0, ref imageInfo).IsTrue());
                    Assert.False(imageInfo.hbmImage.IsNull);
                }
            }
        }
Ejemplo n.º 3
0
        public void ImageList_ImageStream_SetStreamerSerialized_UpdatesImages(ColorDepth colorDepth)
        {
            using var sourceList = new ImageList
                  {
                      ColorDepth = colorDepth,
                      ImageSize  = new Size(32, 32)
                  };
            using var image = new Bitmap(10, 10);
            sourceList.Images.Add(image);
            using ImageListStreamer stream = RoundtripSerialize(sourceList.ImageStream);
            Assert.True(sourceList.HandleCreated);

            using var list = new ImageList();
            int          callCount = 0;
            EventHandler handler   = (sender, e) => callCount++;

            list.RecreateHandle += handler;

            list.ImageStream = stream;
            Assert.Equal(colorDepth, list.ColorDepth);
            Assert.Equal(new Size(32, 32), ((Image)Assert.Single(list.Images)).Size);
            Assert.Equal(new Size(32, 32), list.ImageSize);
            Assert.Equal(0, callCount);
            Assert.True(list.HandleCreated);
            Assert.True(sourceList.HandleCreated);

            // Set same.
            list.ImageStream = stream;
            Assert.Equal(colorDepth, list.ColorDepth);
            Assert.Equal(new Size(32, 32), ((Image)Assert.Single(list.Images)).Size);
            Assert.Equal(new Size(32, 32), list.ImageSize);
            Assert.Equal(1, callCount);
            Assert.True(list.HandleCreated);
            Assert.True(sourceList.HandleCreated);
        }
Ejemplo n.º 4
0
 public ImageListResourceEntryNode(string key, ImageListStreamer data)
 {
     this.LazyLoading      = true;
     this.key              = key;
     this.data             = new ImageList();
     this.data.ImageStream = data;
 }
Ejemplo n.º 5
0
        public void ImageListStreamer_BinaryFormatter_Stream_BinaryFormatter_round_trip_equality()
        {
            // Create an ImageListStreamer via BinaryFormatter
            using ImageListStreamer streamerFromBf  = BinarySerialization.EnsureDeserialize <ImageListStreamer>(ClassicBfImageListStreamer);
            using NativeImageList nativeImageListBf = streamerFromBf.GetNativeImageList();
            Assert.NotEqual(IntPtr.Zero, nativeImageListBf.Handle);

            // Read as a memory stream
            using MemoryStream ms = new();
            streamerFromBf.GetObjectData(ms);
            string msBase64 = Convert.ToBase64String(ms.ToArray());

            // Create a new ImageListStreamer from the stream
            ms.Position = 0;
            using ImageListStreamer streamerFromMs  = new(ms);
            using NativeImageList nativeImageListMs = streamerFromMs.GetNativeImageList();
            Assert.NotEqual(IntPtr.Zero, nativeImageListMs.Handle);

            // Compare the two
            using ImageList imageListBf = new();
            imageListBf.ImageStream     = streamerFromBf;
            using ImageList imageListMs = new();
            imageListMs.ImageStream     = streamerFromMs;

            Assert.Equal(imageListBf.ColorDepth, imageListMs.ColorDepth);
            Assert.Equal(imageListBf.Images.Count, imageListMs.Images.Count);
            Assert.Equal(imageListBf.ImageSize, imageListMs.ImageSize);
        }
Ejemplo n.º 6
0
        internal static string GetBase64ImageList(string filePath)
        {
            ImgListSurr surrogate = new ImgListSurr();

            using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                surrogate.Data = new byte[stream.Length];
                stream.Read(surrogate.Data, 0, surrogate.Data.Length);
            }
            BinaryFormatter formatter = new BinaryFormatter(surrogate, new StreamingContext());

            using (MemoryStream stream = new MemoryStream())
            {
                using (ImageList imglist = new ImageList())
                {
                    imglist.Images.Add(new Bitmap(32, 32));
                    formatter.Serialize(stream, imglist.ImageStream);
                }
                stream.Position = 0;

                BinaryFormatter   b64formatter = new BinaryFormatter();
                ImageListStreamer ils          = (ImageListStreamer)b64formatter.Deserialize(stream);
                stream.SetLength(0);
                b64formatter.Serialize(stream, ils);
                return(Convert.ToBase64String(stream.ToArray()));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Serialize data from the debugee process into the debugger.
        /// </summary>
        public override void GetData(object target, Stream outgoingData)
        {
            ImageList         list        = target as ImageList;
            ImageListStreamer imageStream = (list != null ? list.ImageStream : null);

            // serialize:
            SerializationHelper.WriteAsBinary(outgoingData, imageStream);
        }
        public void NativeImageList_Dispose_releases_native_handle()
        {
            using ImageListStreamer result = BinarySerialization.EnsureDeserialize <ImageListStreamer>(ClassicImageListStreamer);

            NativeImageList nativeImageList = result.GetNativeImageList();

            Assert.NotEqual(IntPtr.Zero, nativeImageList.Handle);

            nativeImageList.Dispose();
            Assert.Equal(IntPtr.Zero, nativeImageList.Handle);
        }
Ejemplo n.º 9
0
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            ImageListStreamer data = objectProvider.GetObject() as ImageListStreamer;
            ImageList         list;

            if (data == null)
            {
                return;
            }
            else
            {
                list             = new ImageList();
                list.ImageStream = data;
            }

            using (Form displayForm = new ImageVisualizerForm(list.Images, list.ImageSize, ImageHelper.AdjustSize(list.ImageSize.Width)))
            {
                windowService.ShowDialog(displayForm);
            }
        }
Ejemplo n.º 10
0
        public void ImageList_ImageStream_SetWithHandleStreamerHasNoHandleNotSerialized_Nop(ColorDepth colorDepth)
        {
            using var sourceList = new ImageList
                  {
                      ColorDepth = colorDepth,
                      ImageSize  = new Size(32, 32)
                  };
            var image = new Bitmap(10, 10);

            sourceList.Images.Add(image);
            ImageListStreamer stream = sourceList.ImageStream;

            using var list = new ImageList();
            Assert.NotEqual(IntPtr.Zero, list.Handle);

            list.ImageStream = stream;
            Assert.Equal(ColorDepth.Depth8Bit, list.ColorDepth);
            Assert.Empty(list.Images);
            Assert.Equal(new Size(16, 16), list.ImageSize);
            Assert.True(list.HandleCreated);
            Assert.False(sourceList.HandleCreated);
        }
Ejemplo n.º 11
0
        public void ImageListStreamer_Stream_BinaryFormatter_compatible()
        {
            // Create a new ImageListStreamer from the stream
            byte[] bytes = Convert.FromBase64String(DevMsImageListStreamer);
            using MemoryStream ms = new(bytes);
            using ImageListStreamer streamerFromMs  = new(ms);
            using NativeImageList nativeImageListMs = streamerFromMs.GetNativeImageList();
            Assert.NotEqual(IntPtr.Zero, nativeImageListMs.Handle);

            // Create an ImageListStreamer via BinaryFormatter
            using ImageListStreamer streamerFromBf  = BinarySerialization.EnsureDeserialize <ImageListStreamer>(ClassicBfImageListStreamer);
            using NativeImageList nativeImageListBf = streamerFromBf.GetNativeImageList();
            Assert.NotEqual(IntPtr.Zero, nativeImageListBf.Handle);

            // Compare the two
            using ImageList imageListBf = new();
            imageListBf.ImageStream     = streamerFromBf;
            using ImageList imageListMs = new();
            imageListMs.ImageStream     = streamerFromMs;

            Assert.Equal(imageListBf.ColorDepth, imageListMs.ColorDepth);
            Assert.Equal(imageListBf.Images.Count, imageListMs.Images.Count);
            Assert.Equal(imageListBf.ImageSize, imageListMs.ImageSize);
        }