Пример #1
0
        /// <summary>
        /// Saves a thumbnail of the video
        /// </summary>
        private void SaveThumbnail()
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                var w = (int)_videoCaptureDevice.PreviewResolution.Width;
                var h = (int)_videoCaptureDevice.PreviewResolution.Height;

                var argbPx = new Int32[w * h];

                _videoCaptureDevice.GetPreviewBufferArgb(argbPx);
                var wb = new WriteableBitmap(w, h);
                argbPx.CopyTo(wb.Pixels, 0);
                wb.Invalidate();

                using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    var fileName = _isoVideoFileName + ".jpg";

                    if (isoStore.FileExists(fileName))
                    {
                        isoStore.DeleteFile(fileName);
                    }

                    var file = isoStore.CreateFile(fileName);
                    wb.SaveJpeg(file, w, h, 0, 20);
                    file.Close();
                }
            });
        }
Пример #2
0
 protected void CountCut(Int32 cutPos)
 {
     // Cut the deck at cutPos, leave the bottom card intact.
     Int32[] newDeck = new Int32[54];
     if (cutPos < 53)
     { // don't cut if the card is a joker
         Array.Copy(_deck, cutPos, newDeck, 0, 53 - (cutPos));
         Array.Copy(_deck, 0, newDeck, 53 - (cutPos), cutPos);
         newDeck[53] = _deck[53];
         newDeck.CopyTo(_deck, 0);
     }
 }
Пример #3
0
        protected void TripleCut()
        {
            // Swaps the section before the top joker with the section after the bottom joker
            Int32 jokerTop    = Array.IndexOf(_deck, 53);
            Int32 jokerBottom = Array.IndexOf(_deck, 54);

            if (jokerTop > jokerBottom)
            {
                Int32 hold = jokerTop;
                jokerTop    = jokerBottom;
                jokerBottom = hold;
            }
            Int32[] newDeck      = new Int32[54];
            Int32   lengthBottom = 53 - jokerBottom;
            Int32   lengthMiddle = jokerBottom - jokerTop - 1;

            Array.Copy(_deck, jokerBottom + 1, newDeck, 0, lengthBottom);
            Array.Copy(_deck, jokerTop, newDeck, lengthBottom, lengthMiddle + 2);
            Array.Copy(_deck, 0, newDeck, lengthBottom + lengthMiddle + 2, jokerTop);
            newDeck.CopyTo(_deck, 0);
        }
Пример #4
0
        private void MethodTests()
        {
            featureTest.FailureMessage = "\tFailed Array Methods Test";
            featureTest.Send("Array Methods Test");
            Int32[] array = new Int32[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            Array.Clear(array, 2, 3);
            featureTest.AssertTrue(array[1] == 2);
            featureTest.AssertTrue(array[2] == 0);
            featureTest.AssertTrue(array[3] == 0);
            featureTest.AssertTrue(array[4] == 0);
            featureTest.AssertTrue(array[5] == 6);

            array = new Int32[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            Int32[] array2 = new Int32[] { 11, 12, 13, 14, 15 };
            Array.ConstrainedCopy(array, 2, array2, 1, 3);
            featureTest.AssertTrue(array2[0] == 11);
            featureTest.AssertTrue(array2[1] == 3);
            featureTest.AssertTrue(array2[2] == 4);
            featureTest.AssertTrue(array2[3] == 5);
            featureTest.AssertTrue(array2[4] == 15);
            Int32[] array3 = new Int32[array.Length];
            Array.Copy(array, array3, array.Length);
            for (Int32 i = 0; i < array.Length; ++i)
            {
                featureTest.AssertTrue(array[i] == array3[i]);
            }
            Array.Clear(array3, 0, array3.Length);
            array.CopyTo(array3, 0);
            for (Int32 i = 0; i < array.Length; ++i)
            {
                featureTest.AssertTrue(array[i] == array3[i]);
            }
            for (Int32 i = 0; i < array.Length; ++i)
            {
                featureTest.AssertTrue(array[i] == array3[i]);
            }
            Array.Copy(array, 0, array3, 0, array.Length);
            featureTest.AssertTrue(int323DArray.GetLength(0) == 2);
            featureTest.AssertTrue(int323DArray.GetLength(1) == 2);
            featureTest.AssertTrue(int323DArray.GetLength(2) == 4);
            featureTest.AssertTrue(int323DArray.GetLowerBound(0) == 0);
            featureTest.AssertTrue(int323DArray.GetLowerBound(1) == 0);
            featureTest.AssertTrue(int323DArray.GetLowerBound(2) == 0);
            featureTest.AssertTrue(int323DArray.GetUpperBound(0) == 1);
            featureTest.AssertTrue(int323DArray.GetUpperBound(1) == 1);
            featureTest.AssertTrue(int323DArray.GetUpperBound(2) == 3);
            featureTest.AssertTrue(!(Boolean)boolean1DArray.GetValue(1));
            featureTest.AssertTrue((Byte)byte1DArray.GetValue(0) == 1);
            featureTest.AssertTrue((Char)char1DArray.GetValue(1) == 'B');
            featureTest.AssertTrue((Double)double1DArray.GetValue(2) == 3.0);
            int161DArray.SetValue((short)6, 3);
            featureTest.AssertTrue((Int16)int161DArray.GetValue(3) == 6);
            featureTest.AssertTrue((Int32)int321DArray.GetValue(4) == 5);
            featureTest.AssertTrue((Int64)int641DArray.GetValue(5) == 6);
            featureTest.AssertTrue((SByte)sbyte1DArray.GetValue(6) == 7);
            featureTest.AssertTrue((Single)single1DArray.GetValue(7) == 8.0F);
            featureTest.AssertTrue((String)string1DArray.GetValue(8) == "Nine");
            featureTest.AssertTrue((UInt16)uint161DArray.GetValue(9) == 0);
            featureTest.AssertTrue((UInt32)uint321DArray.GetValue(0) == 1);
            featureTest.AssertTrue((UInt64)uint641DArray.GetValue(1) == 2);
            featureTest.AssertTrue((DateTime)dateTime1DArray.GetValue(1) == new DateTime(2020, 2, 3, 8, 30, 40));
            featureTest.AssertTrue((TimeSpan)timeSpan1DArray.GetValue(2) == new TimeSpan(7, 8, 9));
            int322DArray.SetValue(9, 1, 1);
            featureTest.AssertTrue((Int32)int322DArray.GetValue(1, 1) == 9);
            featureTest.AssertTrue((Int32)int323DArray.GetValue(1, 1, 1) == 14);
            featureTest.AssertTrue(Array.IndexOf(string1DArray, "Eight") == 7);
            featureTest.AssertTrue(Array.IndexOf(string1DArray, "Eight", 0) == 7);
            featureTest.AssertTrue(Array.IndexOf(string1DArray, "Eight", 0, string1DArray.Length) == 7);

            Int32[,,] array3d = new Int32[2, 2, 4];
            Int32[] indexes = new Int32[] { 1, 1, 2 };
            array3d.SetValue(22, indexes);
            featureTest.AssertTrue(array3d[1, 1, 2] == 22);
            featureTest.AssertTrue((Int32)array3d.GetValue(indexes) == 22);
            array3d.SetValue(25, 0, 0, 1);
            featureTest.AssertTrue(array3d[0, 0, 1] == 25);
        }
Пример #5
0
        private static void MostrarArrays()
        {
            Console.Clear();
            Console.WriteLine("*********************************************");
            Console.WriteLine("***********Arrays en CSharp******************");
            Console.WriteLine("*********************************************");
            Console.ReadLine();

            //DECLARO UN ARRAY DE ENTEROS
            int[] numeros;

            ushort num      = 0;
            bool   esValido = false;

            Console.Write("¿Cuántos numeros va a introducir? ");

            esValido = UInt16.TryParse(Console.ReadLine(), out num);

            while (esValido == false)
            {
                Console.WriteLine("Error, Reingrese un número positivo!!!");
                esValido = UInt16.TryParse(Console.ReadLine(), out num);
            }

            //INSTANCIO EL ARRAY DE ENTEROS
            numeros = new Int32[num];

            //CARGO EL ARRAY CON VALORES, UTILIZANDO UN FOR
            for (int i = 0; i < num; i++)
            {
                Console.Write("Ingrese el número para el elemento {0}: ", i);
                numeros[i] = int.Parse(Console.ReadLine());
            }

            Console.WriteLine();
            Console.WriteLine("Pulse una tecla para ver el contenido del Array...");
            Console.WriteLine("Utilizando una estructura For Each...");
            Console.ReadLine();

            //MUESTRO EL CONTENIDO DEL ARRAY, UTILIZO UN FOREACH
            int index = 0;

            foreach (int i in numeros)
            {
                Console.WriteLine("Elemento {0}: {1}", index, i);
                index++;
            }

            Console.ReadLine();
            Console.Clear();

            int cantidad;

            //DECLARO E INSTANCIO OTRO ARRAY DE ENTEROS
            int[] n = new int[num];

            //COPIO EL CONTENIDO DEL PRIMER ARRAY EN EL SEGUNDO
            numeros.CopyTo(n, 0);

            Console.WriteLine("Copio el contenido del Array en un nuevo Array llamado 'n'.");
            Console.ReadLine();

            //MUESTRO EL CONTENIDO DEL SEGUNDO ARRAY, UTILIZO UN FOR
            //OBTENGO LA CANTIDAD DE ELEMENTOS UTILIZANDO GETLENGTH
            for (int i = 0; i < n.GetLength(0); i++)
            {
                Console.WriteLine("Elemento {0}: {1}", i, n[i]);
            }
            Console.ReadLine();

            //OBTENGO EL LIMITE INFERIOR DEL ARRAY
            cantidad = n.GetLowerBound(0);

            Console.WriteLine("n.GetLowerBound(0) = {0}", cantidad);
            Console.ReadLine();

            //OBTENGO EL LIMITE SUPERIOR DEL ARRAY
            cantidad = n.GetUpperBound(0);

            Console.WriteLine("n.GetUpperBound(0) = {0}", cantidad);
            Console.ReadLine();

            //OBTENGO EL VALOR DE UN ELEMENTO UTILIZANDO GETVALUE
            Console.WriteLine("n.GetValue(num-1) = {0}", n.GetValue(num - 1));
            Console.ReadLine();

            //ESTABLEZCO EL VALOR DE UN ELEMENTO UTILIZANDO SETVALUE
            n.SetValue(99, num - 1);

            Console.WriteLine("n.SetValue(99, num - 1), --> {0}", n.GetValue(num - 1));
            Console.ReadLine();
            Console.Clear();

            UInt16 filas;
            UInt16 columnas;

            do
            {
                Console.WriteLine("Ingrese cantidad de filas para el Array.");
            } while (!UInt16.TryParse(Console.ReadLine(), out filas));


            do
            {
                Console.WriteLine("Ingrese cantidad de columnas para el Array.");
            } while (!UInt16.TryParse(Console.ReadLine(), out columnas));

            //DECLARO E INSTANCIO UN ARRAY MULTIDIMENCIONAL
            //DE DOS FILAS Y DOS COLUMNAS
            int[,] matriz = new int[filas, columnas];

            Console.Clear();
            Console.WriteLine("Creo un Array multidimensional.");
            Console.WriteLine("Muestro la cantidad de dimensiones del Array.");
            Console.ReadLine();

            Console.WriteLine("El Array posee {0} dimensiones.", matriz.Rank);
            Console.ReadLine();

            Console.WriteLine("Muestro la cantidad total de elementos del Array.");

            Console.WriteLine("El Array posee {0} elementos sumando todas sus dimensiones."
                              , matriz.Length);
            Console.ReadLine();
        }