//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!");
        }
Example #2
0
        // https://developer.android.com/reference/android/graphics/Color
        public override (int a, int r, int g, int b) GetPixel(int x, int y)
        {
            var color = platformBitmap.GetPixel(x, y);
            int a     = (color >> 24) & 0xff;
            int r     = (color >> 16) & 0xff;
            int g     = (color >> 8) & 0xff;
            int b     = (color) & 0xff;

            return(a, r, g, b);
        }
Example #3
0
        public Color GetPixel(int x, int y)
        {
            int pixel = ABitmap.GetPixel(x, y);

            int red   = Android.Graphics.Color.GetRedComponent(pixel);
            int blue  = Android.Graphics.Color.GetBlueComponent(pixel);
            int green = Android.Graphics.Color.GetGreenComponent(pixel);

            return(Color.FromArgb(red, green, blue));
        }
Example #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            SetContentView(Resource.Layout.ScaleImage);

            // Register our sensor listener
            _sensorManager = (SensorManager) GetSystemService(SensorService);
            _sensorListener = new CustomListener(_sensorManager);
            _sensorListener.AccelerationProcessor.OnValueChanged += AccelerationProcessorOnValueChanged;
            _sensorListener.RotationProcessor.OnValueChanged += RotationProcessorOnValueChanged;

            // Class that will handle drawing of the map
            _mapMaker = new MapMaker();
            _mapMaker.Initialize(Resources);

            var graphAsset = Assets.Open("dcsGroundFloor.xml");
            var graphInstance = Graph.Load(graphAsset);

            _mapMaker.PathfindingGraph = graphInstance;

            _collision = new Collision(graphInstance, new StepDetector());
            _collision.SetLocation(707.0f, 677.0f);
            _collision.PassHeading(90);
            
            _collision.PositionChanged += CollisionOnPositionChanged;
            _collision.StepDetector.OnStep += StepDetectorOnStep;

            collisionMap = BitmapFactory.DecodeResource(Resources,Resource.Drawable.dcsFloor);

            _walCol = new WallCollision((x,y)=>collisionMap.GetPixel(x,y));
            _collision.WallCol = _walCol;


            pf = new Pathfinding.Pathfinding(new Dictionary<int, Stream>()
            {
                {0,Assets.Open("dcsGroundFloor.xml") },
                {1,Assets.Open("dcsFloor1.xml") }
            },Assets.Open("Rooms.xml") );
            pf.CurrentFloor = 0;


            while (true)
            {
                if (pf.Ready)
                    break;
                Thread.Sleep(500);
            }

            var result = pf.FindPath(new GraphLocatable(609, 457, 1), new GraphLocatable(1256, 80, 0));


            setUpUITabs();
        }
 //Calculate White Pixels pixels, Called above in OnActivityResult
 //Arbitrary function, will be replaced
 public string Pix(Bitmap BM)
 {
     //Calculate # of Pixels
     int x = 0;
     int y = 0;
     int WhiteCount = 0;
     while (y < BM.Height) {
         while (x < BM.Width) {
             if (BM.GetPixel (x, y) == -1) {
                 WhiteCount++;
             }
             x++;
         }
         x = 0;
         y++;
     }
     return ("White Pixels:" + WhiteCount);
 }
        // 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();
        }
Example #7
0
	    private static List<Div> GetXDivs(Bitmap bitmap, int raw) {
		   var xDivs = new List<Div>();
		    Div tmpDiv = null;
		    for (int i = 1; i < bitmap.Width; i++) {
			    tmpDiv = ProcessChunk(bitmap.GetPixel(i, raw), tmpDiv, i - 1, xDivs);
		    }
		    return xDivs;
	    }
Example #8
0
        private static List<Div> GetYDivs(Bitmap bitmap, int column) {
		    var yDivs = new List<Div>();
		    Div tmpDiv = null;
		    for (int i = 1; i < bitmap.Height; i++) {
			    tmpDiv = ProcessChunk(bitmap.GetPixel(column, i), tmpDiv, i - 1, yDivs);
		    }
		    return yDivs;
	    }
Example #9
0
 private static bool HasSameColor(Bitmap bitmap, int startX, int stopX, int startY, int stopY)
 {
     int color = bitmap.GetPixel(startX, startY);
     for (int x = startX; x <= stopX; x++)
     {
         for (int y = startY; y <= stopY; y++)
         {
             if (color != bitmap.GetPixel(x, y))
                 return false;
         }
     }
     return true;
 }
Example #10
0
        /// <summary>
        /// Setup colors.
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="chunck"></param>
        private static void SetupColors(Bitmap bitmap, NinePatchChunk chunck)
        {            		
		    int bitmapWidth = bitmap.Width - 2;
		    int bitmapHeight = bitmap.Height - 2;
		    var xRegions = GetRegions(chunck.xDivs, bitmapWidth);
		    var yRegions = GetRegions(chunck.yDivs, bitmapHeight);
		    chunck.colors = new int[xRegions.Count * yRegions.Count];

		    int colorIndex = 0;
		    foreach (Div yDiv in yRegions) {
			    foreach (Div xDiv in xRegions) {
				    int startX = xDiv.start + 1;
				    int startY = yDiv.start + 1;
				    if (HasSameColor(bitmap, startX, xDiv.stop + 1, startY, yDiv.stop + 1)) {
					    int pixel = bitmap.GetPixel(startX, startY);
					    if (isTransparent(pixel))
						    pixel = TRANSPARENT_COLOR;
					    chunck.colors[colorIndex] = pixel;
				    } else {
                        chunck.colors[colorIndex] = NO_COLOR;
				    }
				    colorIndex++;
			    }
		    }
        }
Example #11
0
        private int[][] getPixelsSlow(Bitmap image)
        {
            int width = image.Width;
            int height = image.Height;
            int[][] result = new int[height][];
            for (int row = 0; row < height; row++) {
                result [row] = new int[width];
                for (int col = 0; col < width; col++) {
                    int clr= image.GetPixel (col,row);

                    Color c = new Color (clr);
                    //Console.WriteLine ("{0} {1}",clr,c.ToString());
                    result [row] [col] = c.ToArgb ();
                }
            }

            return result;
        }