Ejemplo n.º 1
0
        public MainPage()
        {
            temp = new C2n();
            temp.initRGB_HSL();

            hc = temp.clr_name("#FBF84B");


            this.InitializeComponent();
            textblock1.Text = hc.name_closest;
        }
Ejemplo n.º 2
0
        private void image1_Tapped(object sender, TappedRoutedEventArgs e)
        {
            /* var rass1 = RandomAccessStreamReference.CreateFromUri(new System.Uri("Assert/cvet.jpg")); */
            /* IRandomAccessStream stream1 = await rass1.OpenReadAsync(); */

            /* http://msdn.microsoft.com/en-us/library/hh763341.aspx */



            /*im.GetPixel POSTOJI =D dakle ucitam sliku uzmem pixel , sledece je da se prevede u zvuk */
            /* IRandomAccessStream strSrc; */
            /* im.SetSource(strSrc); */
            /*Za najbolje performanse (real time scenario) implementirati njegov kod direktno u petlji*/
            Point  p     = e.GetPosition(image1);
            Color  clr   = slika.GetPixel(Convert.ToInt32(p.X), Convert.ToInt32(p.Y));
            String temp2 = Color2Hex(clr);

            hc = temp.clr_name(temp2);
            textblock1.Text = hc.name_shade;
        }
Ejemplo n.º 3
0
        internal async void captureclr_Click(object sender, RoutedEventArgs e)
        {
            // FOR Performance
            // m_mediaCaptureMgr.PrepareLowLagPhotoCaptureAsync



            //m_mediaCaptureMgr.CapturePhotoToStreamAsync
            captureclr.IsEnabled = false;


            /*Need to fix when it breaks cause of fast taping to take the image SystemExeption*/
            try
            {
                await m_mediaCaptureMgr.CapturePhotoToStreamAsync(ie_prop, i_rs);
            }
            catch (Exception exp)
            {
                // TODO implement error functions
            }


            /*This fuckign line is so important , or else WB trows exeptions all round the house */
            i_rs.Seek(0);

            /* Losing the aspect ratio because we set both decode pixel width and heigth  */
            // if u want bitmap image

            /*
             * BitmapImage bi = new BitmapImage();
             * bi.DecodePixelHeight = (int) previewElement1.Height;
             * bi.DecodePixelWidth = (int) previewElement1.Width;
             * bi.SetSource(i_rs);
             */
            /* Now to change the bitmapimage to writeablebitmap image*/


            //wHERE the hell is a WriteableBitmap constructor from BitmapImage
            //BitmapImage bi = new BitmapImage();

            //await bi.SetSourceAsync(i_rs);
            WriteableBitmap wb = new WriteableBitmap((int)previewElement1.ActualWidth, (int)previewElement1.ActualHeight);

            //TODO go direct to writeablebitmap if possible
            //wb.SetSource(i_rs);
            await wb.SetSourceAsync(i_rs);

            /* Now we need to pull out the pixels (using writeablebitmapEX class)
             * pulling out every 9th pixel but none on the edges so thats 9x9=81 pixels for a 90x90 square
             */
            Color[,] rgb_array = new Color[9, 9];
            // 180 is both left and top from both canvas and capture element

            Dictionary <String, int> mapa = new Dictionary <string, int>();

            //For debuging purposes
            Dictionary <HelperColor, int> mapa_hc = new Dictionary <HelperColor, int>();

            for (int i = 9; i < 90; i = i + 9)
            {
                for (int j = 9; j < 90; j = j + 9)
                {
                    // TODO FIX wb.getpixel returning null ?!

                    rgb_array[(i - 9) / 9, (j - 9) / 9] = wb.GetPixel(180 + i, 180 + j);
                }
            }
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    HelperColor hc = temp.clr_name(Color2Hex(rgb_array[i, j]));
                    if (!mapa_hc.ContainsKey(hc))
                    {
                        mapa_hc.Add(hc, 1);
                    }
                    else
                    {
                        mapa_hc[hc]++;
                    }
                    if (!mapa.ContainsKey(hc.name_shade))
                    {
                        mapa.Add(hc.name_shade, 1);
                    }
                    else
                    {
                        mapa[hc.name_shade]++;
                    }
                }
            }

            /*To search for the shadename that ocured the most */

            /*Benchmark estimated to 125+ ms which is allot for iteraating thorugh map *
             * TODO create an array variable for this kind of stuff
             */
            String placeholder = "";
            int    max_        = 0;

            foreach (KeyValuePair <String, int> kv in mapa)
            {
                if (max_ < kv.Value)
                {
                    max_        = kv.Value;
                    placeholder = kv.Key;
                }
            }
            textblock1.Text = placeholder;

            captureclr.IsEnabled = true;

            // Throws error , cannot convert windows smth uri to smth
            //m_mediael.Source = this.c2u.GetSoundUri(placeholder);
            //m_mediael.Play();
        }