public void TestThatClipboardControllerIgnoresNonImageDataInClipboard()
        {
            Clipboard.Clear();
            Clipboard.SetText("Text data");
            var img = ClipboardController.GetImageFromClipboard();

            Assert.Null(img);
        }
示例#2
0
        public void TestThatClipboardControllerIgnoresNonImageDataInClipboard()
        {
            Clipboard.Clear();
            Clipboard.SetText(Text);
            WriteableBitmap img = ClipboardController.GetImageFromClipboard();

            Assert.Null(img);
        }
        public void TestThatClipboardControllerGetsCorrectImageInDibFormatFromClipboard()
        {
            Clipboard.Clear();
            var bmp = BitmapFactory.New(10, 10);

            bmp.SetPixel(4, 4, testColor);
            Clipboard.SetImage(bmp);

            var img = ClipboardController.GetImageFromClipboard();

            Assert.NotNull(img);
            Assert.Equal(10, img.PixelWidth);
            Assert.Equal(10, img.PixelHeight);
            Assert.Equal(testColor, bmp.GetPixel(4, 4));
        }
        public void TestThatClipboardControllerGetsCorrectImageInBitmapFormatFromClipboard()
        {
            Clipboard.Clear();
            var bmp = BitmapFactory.New(10, 10);

            bmp.SetPixel(4, 4, testColor);

            DataObject data = new DataObject();

            data.SetData(DataFormats.Bitmap, bmp, false); //PNG, supports transparency
            Clipboard.SetDataObject(data, true);

            var img = ClipboardController.GetImageFromClipboard();

            Assert.NotNull(img);
            Assert.Equal(10, img.PixelWidth);
            Assert.Equal(10, img.PixelHeight);
            Assert.Equal(testColor, bmp.GetPixel(4, 4));
        }
        public void TestThatClipboardControllerGetsCorrectImageInPngFormatFromClipboard()
        {
            Clipboard.Clear();
            var bmp = BitmapFactory.New(10, 10);

            bmp.SetPixel(4, 4, testColor);
            using (var pngStream = new MemoryStream())
            {
                DataObject data = new DataObject();

                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));
                encoder.Save(pngStream);
                data.SetData("PNG", pngStream, false); //PNG, supports transparency
                Clipboard.SetDataObject(data, true);
            }

            var img = ClipboardController.GetImageFromClipboard();

            Assert.NotNull(img);
            Assert.Equal(10, img.PixelWidth);
            Assert.Equal(10, img.PixelHeight);
            Assert.Equal(testColor, bmp.GetPixel(4, 4));
        }