//Create the remove red button
        private void NoRed(object sender, System.EventArgs e)
        {
            TextView  tv_saved  = FindViewById <TextView>(Resource.Id.respondText);
            ImageView imageView = FindViewById <ImageView>(Resource.Id.takenPictureImageView);
            int       height    = Resources.DisplayMetrics.HeightPixels;
            int       width     = imageView.Height;

            Android.Graphics.Bitmap bitmap     = _file.Path.LoadAndResizeBitmap(width, height);
            Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true);
            for (int i = 0; i < copyBitmap.Width; i++)
            {
                for (int j = 0; j < copyBitmap.Height; j++)
                {
                    int p = copyBitmap.GetPixel(i, j);
                    //00000000 00000000 00000000 00000000
                    //long mask = (long)0xFF00FFFF;
                    //p = p & (int)mask;
                    Android.Graphics.Color c = new Android.Graphics.Color(p);
                    c.R = 0;
                    copyBitmap.SetPixel(i, j, c);
                }
            }
            if (bitmap != null)
            {
                imageView.SetImageBitmap(copyBitmap);
                imageView.Visibility = Android.Views.ViewStates.Visible;
            }

            System.GC.Collect();
            tv_saved.SetTextKeepState("Red Removed!");
        }
Esempio n. 2
0
        public override void SetPixel(int x, int y, int a, int r, int g, int b)
        {
            Color color = new Color(r, g, b, a);

            platformBitmap.SetPixel(x, y, color);
        }
        // Called automatically whenever an activity finishes
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            SetContentView(Resource.Layout.PicManip);
            bool reverted = true;


            Button remred    = FindViewById <Button>(Resource.Id.RemRed);
            Button remgreen  = FindViewById <Button>(Resource.Id.RemGreen);
            Button remblue   = FindViewById <Button>(Resource.Id.RemBlue);
            Button negred    = FindViewById <Button>(Resource.Id.NegRed);
            Button neggreen  = FindViewById <Button>(Resource.Id.NegGreen);
            Button negblue   = FindViewById <Button>(Resource.Id.NegBlue);
            Button greyscale = FindViewById <Button>(Resource.Id.Greyscale);
            Button high_cont = FindViewById <Button>(Resource.Id.HighContrast);
            Button add_noise = FindViewById <Button>(Resource.Id.AddNoise);
            Button revert    = FindViewById <Button>(Resource.Id.Revert);
            Button save      = FindViewById <Button>(Resource.Id.Save);

            //test to make sure the picture was found
            if ((resultCode == Result.Ok) && (data != null))
            {
                //Make image available in the gallery
                //Test to see if we came from the camera or gallery
                //If we came from galley no need to make pic available
                if (requestCode == 0)
                {
                    Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                    var    contentUri      = Android.Net.Uri.FromFile(_file);
                    mediaScanIntent.SetData(contentUri);
                    SendBroadcast(mediaScanIntent);
                }
            }

            // Display in ImageView. We will resize the bitmap to fit the display.
            // Loading the full sized image will consume too much memory
            // and cause the application to crash.
            ImageView imageView = FindViewById <ImageView>(Resource.Id.takenPictureImageView);
            int       height    = Resources.DisplayMetrics.HeightPixels;
            int       width     = imageView.Height;

            bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data");
            bitmap = Android.Graphics.Bitmap.CreateScaledBitmap(bitmap, 1024, 768, true);

            //check to make sure the bitmap has data we can manipulate
            if (bitmap != null)
            {
                copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true);
                imageView.SetImageBitmap(copyBitmap);
            }

            else
            {
                //If bitmap is null takes the user back to the original screen
                StartMainLayout();
            }

            //Removes the red in the picture by setting the red pixel to 0
            remred.Click += delegate
            {
                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int p = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);

                        c.R = 0;
                        copyBitmap.SetPixel(i, j, c);
                    }
                }

                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Removes the green in the picture by setting the green pixel to 0
            remgreen.Click += delegate
            {
                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int p = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);

                        c.G = 0;
                        copyBitmap.SetPixel(i, j, c);
                    }
                }

                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Removes the blue in the picture by setting the blue pixel to 0
            remblue.Click += delegate
            {
                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int p = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);

                        c.B = 0;
                        copyBitmap.SetPixel(i, j, c);
                    }
                }

                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Negates the red in the picture by subtracting 255 from the current red pixels value
            negred.Click += delegate
            {
                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int p = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);
                        int r1 = c.R;
                        r1  = 255 - r1;
                        c.R = Convert.ToByte(r1);
                        copyBitmap.SetPixel(i, j, c);
                    }
                }

                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Negates the green in the picture by subtracting 255 from the current green pixels value
            neggreen.Click += delegate
            {
                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int p = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);
                        int g1 = c.G;
                        g1  = 255 - g1;
                        c.G = Convert.ToByte(g1);
                        copyBitmap.SetPixel(i, j, c);
                    }
                }

                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Negates the blue in the picture by subtracting 255 from the current blue pixels value
            negblue.Click += delegate
            {
                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int p = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);
                        int b1 = c.B;
                        b1  = 255 - b1;
                        c.B = Convert.ToByte(b1);
                        copyBitmap.SetPixel(i, j, c);
                    }
                }

                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Converts the picture to greyscale by averaging all the pixels values
            //Then setting the each pixel to the average
            greyscale.Click += delegate
            {
                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int average = 0;
                        int p       = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);
                        int r_temp = c.R;
                        int g_temp = c.G;
                        int b_temp = c.B;

                        average = (r_temp + g_temp + b_temp) / 3;

                        c.R = Convert.ToByte(average);
                        c.G = Convert.ToByte(average);
                        c.B = Convert.ToByte(average);
                        copyBitmap.SetPixel(i, j, c);
                    }
                }
                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Converts the picture to high contrast
            //If the pixel > 127.5, then set to 255, else set to 0
            high_cont.Click += delegate
            {
                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int check_num            = 255 / 2;
                        int p                    = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);
                        int r_temp               = c.R;
                        int g_temp               = c.G;
                        int b_temp               = c.B;

                        if (r_temp > check_num)
                        {
                            r_temp = 255;
                        }

                        else
                        {
                            r_temp = 0;
                        }

                        if (g_temp > check_num)
                        {
                            g_temp = 255;
                        }

                        else
                        {
                            g_temp = 0;
                        }

                        if (b_temp > check_num)
                        {
                            b_temp = 255;
                        }

                        else
                        {
                            b_temp = 0;
                        }

                        c.R = Convert.ToByte(r_temp);
                        c.G = Convert.ToByte(g_temp);
                        c.B = Convert.ToByte(b_temp);
                        copyBitmap.SetPixel(i, j, c);
                    }
                }
                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Adds random noise to the picture
            //Get a random value from -10 - 10, and add it to the pixels value
            //making sure the pixel value doesn't go over 255 or under 0.
            add_noise.Click += delegate
            {
                Random rnd = new Random();

                for (int i = 0; i < copyBitmap.Width; i++)
                {
                    for (int j = 0; j < copyBitmap.Height; j++)
                    {
                        int p = copyBitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);
                        int rand_val             = rnd.Next(-10, 11);
                        int r_temp = c.R;
                        int g_temp = c.G;
                        int b_temp = c.B;

                        r_temp += rand_val;
                        g_temp += rand_val;
                        b_temp += rand_val;

                        if (r_temp > 255)
                        {
                            r_temp = 255;
                        }
                        else if (r_temp < 0)
                        {
                            r_temp = 0;
                        }

                        if (g_temp > 255)
                        {
                            g_temp = 255;
                        }
                        else if (g_temp < 0)
                        {
                            g_temp = 0;
                        }

                        if (b_temp > 255)
                        {
                            b_temp = 255;
                        }
                        else if (b_temp < 0)
                        {
                            b_temp = 0;
                        }

                        c.R = Convert.ToByte(r_temp);
                        c.G = Convert.ToByte(g_temp);
                        c.B = Convert.ToByte(b_temp);
                        copyBitmap.SetPixel(i, j, c);
                    }
                }

                imageView.SetImageBitmap(copyBitmap);
                reverted = false;
            };

            //Button used to revert the image effects back to the orginal picture
            revert.Click += delegate
            {
                if (bitmap != null && !reverted)
                {
                    copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true);
                    imageView.SetImageBitmap(copyBitmap);
                    reverted = true;
                }

                else if (reverted)
                {
                    Toast.MakeText(this, "The picture is the original.", ToastLength.Short).Show();
                }
            };

            //Saves the image to the users gallery
            save.Click += delegate
            {
                var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
                var filePath   = System.IO.Path.Combine(sdCardPath, "ImageManip_{0}.png");
                var stream     = new FileStream(filePath, FileMode.Create);
                copyBitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
                stream.Close();
                Toast.MakeText(this, "The picture was saved to gallery.", ToastLength.Short).Show();

                StartMainLayout();
            };

            // Dispose of the Java side bitmap.
            System.GC.Collect();
        }
Esempio n. 4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Start);
            lista = LDbConnection.GetActualUserExpo();
            var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetDisplayShowTitleEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu);
            drawerLayout   = FindViewById <Android.Support.V4.Widget.DrawerLayout>(Resource.Id.drawer_layout);
            navigationView = FindViewById <Android.Support.Design.Widget.NavigationView>(Resource.Id.nav_view);
            navigationView.NavigationItemSelected += HomeNavigationView_NavigationItemSelected;
            var    qrcode = FindViewById <Android.Widget.ImageView>(Resource.Id.Start_qrcode);
            var    writer = new ZXing.QrCode.QRCodeWriter();
            String s      = "";

            if (LDbConnection.getUserType() == "Uczestnik")
            {
                s = "Uczestnik:" + LDbConnection.GetUser().Email;
            }
            else if (LDbConnection.getUserType() == "Wystawca")
            {
                s = "Wystawca:" + LDbConnection.GetCompany().Email;
            }
            ZXing.Common.BitMatrix  bm          = writer.encode(s, ZXing.BarcodeFormat.QR_CODE, 500, 500);
            Android.Graphics.Bitmap ImageBitmap = Android.Graphics.Bitmap.CreateBitmap(500, 500, Config.Argb8888);

            for (int i = 0; i < 500; i++)
            {     //width
                for (int j = 0; j < 500; j++)
                { //height
                    ImageBitmap.SetPixel(i, j, bm[i, j] ? Color.Black : Color.White);
                }
            }

            if (ImageBitmap != null)
            {
                qrcode.SetImageBitmap(ImageBitmap);
            }
            var expo_list = FindViewById <Android.Widget.Spinner>(Resource.Id.Start_targi);

            expo_list.ItemSelected += new System.EventHandler <Android.Widget.AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
            var adapter = new MyExpoSingleListViewAdapter(lista, this);

            expo_list.Adapter = adapter;
            var btn1 = (Button)FindViewById(Resource.Id.Start_join);

            btn1.Visibility = Android.Views.ViewStates.Invisible;
            btn1.Click     += delegate
            {
                var NxtAct = new Android.Content.Intent(this, typeof(UserActivity));
                StartActivity(NxtAct);
            };
            var button = FindViewById <Android.Widget.Button>(Resource.Id.Start_scan);

            button.Click += async delegate
            {
                ZXing.Mobile.MobileBarcodeScanner scanner;
                ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);
                scanner = new ZXing.Mobile.MobileBarcodeScanner();
                scanner.UseCustomOverlay = false;

                //We can customize the top and bottom text of the default overlay
                scanner.BottomText = "Poczekaj, aż kod kreskowy będzie automatycznie zeskanowany!";

                //Start scanning
                var result = await scanner.Scan();

                scanner.Cancel();
                if (result == null)
                {
                    scanner.Cancel();
                }
                else
                {
                    scanner.Cancel();
                    string[] scan = result.Text.Split(':');
                    if (scan[0] == "Wystawca")
                    {
                        var NxtAct = new Android.Content.Intent(this, typeof(CompanyActivity));
                        NxtAct.PutExtra("Email", scan[1]);
                        NxtAct.PutExtra("expo_id", lista[select].Id);
                        NxtAct.PutExtra("Search", result.Text);
                        NxtAct.PutExtra("Show", true);

                        StartActivity(NxtAct);
                    }
                    else if (scan[0].Contains("Uczestnik"))
                    {
                        System.Console.WriteLine("Uczestnik");
                        var NxtAct = new Android.Content.Intent(this, typeof(UserActivity));
                        NxtAct.PutExtra("Email", scan[1]);
                        NxtAct.PutExtra("expo_id", lista[select].Id);
                        NxtAct.PutExtra("Search", result.Text);
                        NxtAct.PutExtra("Show", true);

                        StartActivity(NxtAct);
                    }
                }
            };
            if (lista == null)
            {
                button.Visibility = Android.Views.ViewStates.Invisible;
                btn1.Visibility   = Android.Views.ViewStates.Visible;
            }
        }
Esempio n. 5
0
        public void SetPixel(int x, int y, Color color)
        {
            Android.Graphics.Color c = new Android.Graphics.Color(color.R, color.G, color.B);

            ABitmap.SetPixel(x, y, c);
        }