public void OnFrameCaptured(Image image)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         ImageBox.Source = BitmapConverters.ImageToBitmap(image);
     });
 }
Exemplo n.º 2
0
        [Test] // Tests a singular bitmap to gif conversion
        public void TestBitmapToGifConversion()
        {
            // Generate a random 20 x 20 bitmap
            Bitmap bmp     = new Bitmap(20, 20);
            Random r       = new Random();
            string gifPath = "TestBitmapToGifConversion.gif";

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(r.Next()));
                }
            }

            List <Bitmap> inputList = new List <Bitmap>();

            inputList.Add(bmp);

            // Save the bitmap as a gif
            BitmapConverters.SaveBitmapsAsAnimatedGIF(inputList, gifPath, 1);

            // Convert the gif back into a bitmap
            FileStream    gifStream  = new FileStream(gifPath, FileMode.Open);
            List <Bitmap> outputList = BitmapConverters.CreateBitmapsFromGIF(gifStream);

            gifStream.Close();

            // Clean up gif
            if (File.Exists(gifPath))
            {
                File.Delete(gifPath);
            }

            // Verify that there is one bitmap in the output list
            AreEqual(outputList.Count, 1);

            Bitmap gif = outputList[0];

            // Check that the two bitmap's sizes are identical
            AreEqual(bmp.Width, gif.Width);
            AreEqual(bmp.Height, gif.Height);

            // Check that the two bitmap's pixels are identical, assuming that the sizes are identical
            if (bmp.Size == gif.Size)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        AreEqual(bmp.GetPixel(x, y), gif.GetPixel(x, y));
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void NativeScalingTest()
        {
            // Generate a randomly scaled 20 x 20 bitmap

            Random r           = new Random();
            int    nativeScale = r.Next(2, 11);
            Bitmap bmp         = new Bitmap(20 * nativeScale, 20 * nativeScale);
            string pngPath     = "NativeScalingTest.png";

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(r.Next()));
                }
            }

            // Save as a .png temporarily
            FileStream bmpFile = new FileStream(pngPath, FileMode.Create);

            BitmapConverters.SaveBitmapAsPNG(bmp, bmpFile);
            bmpFile.Close();

            // Convert the saved png back into a bitmap
            FileStream pngFile = new FileStream(pngPath, FileMode.Open);

            // Create a grid from the png saved
            DrawingGrid grid = new DrawingGrid(pngFile, 2, nativeScale);

            pngFile.Close();

            // Clean up png
            if (File.Exists(pngPath))
            {
                File.Delete(pngPath);
            }

            // Verify that the grid maintains the same parameters
            AreEqual(grid.Scale, 2);
            AreEqual(grid.size.Width, 20);
            AreEqual(grid.size.Height, 20);
            AreEqual(grid.Grid.GetLength(0), 20);
            AreEqual(grid.Grid.GetLength(1), 20);

            // Verify that the interior grid has the same colors as the bitmap saved
            for (int x = 0; x < 20; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    AreEqual(grid.GetCell(x, y), bmp.GetPixel(x * nativeScale, y * nativeScale));
                }
            }
        }
Exemplo n.º 4
0
        public void TestBitmapToPngConversion()
        {
            // Generate a random 20 x 20 bitmap
            Bitmap bmp     = new Bitmap(20, 20);
            Random r       = new Random();
            string pngPath = "TestBitmapToPngConversion.png";

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(r.Next()));
                }
            }

            // Save as a .png temporarily
            FileStream bmpFile = new FileStream(pngPath, FileMode.Create);

            BitmapConverters.SaveBitmapAsPNG(bmp, bmpFile);
            bmpFile.Flush();
            bmpFile.Close();

            // Convert the saved png back into a bitmap
            FileStream pngFile = new FileStream(pngPath, FileMode.Open);
            Bitmap     png     = BitmapConverters.CreateBitmapFromPNG(pngFile);

            pngFile.Close();

            // Clean up png
            if (File.Exists(pngPath))
            {
                File.Delete(pngPath);
            }

            // Check that the two bitmap's sizes are identical
            AreEqual(bmp.Width, png.Width);
            AreEqual(bmp.Height, png.Height);

            // Check that the two bitmap's pixels are identical, assuming that the sizes are identical
            if (bmp.Size == png.Size)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        AreEqual(bmp.GetPixel(x, y), png.GetPixel(x, y));
                    }
                }
            }
        }
 private void ExecuteAddProduct()
 {
     using (UnitOfWork context = new UnitOfWork())
     {
         try
         {
             _product.Weight      += "g";
             _product.Height      += "mm";
             _product.Width       += "mm";
             _product.Picture_Main = BitmapConverters.ConvertBitmapSourceToByteArray(_picture_Main_Path);
             _product.Picture1     = BitmapConverters.ConvertBitmapSourceToByteArray(_picture1_Path);
             _product.Picture2     = BitmapConverters.ConvertBitmapSourceToByteArray(_picture2_Path);
             _product.MenuPicture  = BitmapConverters.ConvertBitmapSourceToByteArray(_menuPicture_Path);
             context.ProductRepository.AddProduct(_product);
             context.SaveChanges();
             NotificationWindowContoller.NewNotification("Success!", "Product added successfully!", Notification.NotificationType.Success);
         }
         catch
         {
             NotificationWindowContoller.NewNotification("Error!", "Fail to add product!", Notification.NotificationType.Danger);
         }
     }
 }
Exemplo n.º 6
0
        public void TestBitmapToSourceConversion()
        {
            // Generate a random 20 x 20 bitmap
            Bitmap bmp = new Bitmap(20, 20);
            Random r   = new Random();

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(r.Next()));
                }
            }

            // Generate source from bitmap
            BitmapSource source = BitmapConverters.CreateSourceFromBitmap(bmp);

            // Recreate bitmap from source
            Bitmap newBmp = BitmapConverters.CreateBitmapFromSource(source);

            // Check that the two bitmap's sizes are identical
            AreEqual(bmp.Width, newBmp.Width);
            AreEqual(bmp.Height, newBmp.Height);

            // Check that the two bitmap's pixels are identical, assuming that the sizes are identical
            if (bmp.Size == newBmp.Size)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        AreEqual(bmp.GetPixel(x, y), newBmp.GetPixel(x, y));
                    }
                }
            }
        }
Exemplo n.º 7
0
 public void RegisterPlatform()
 {
     ViewStatesConverters.Register(this);
     ColorConverters.Register(this);
     BitmapConverters.Register(this);
 }