// <summary> // Called automatically whenever an activity finishes // </summary> // <param name = "requestCode" ></ param > // < param name="resultCode"></param> /// <param name="data"></param> protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); //Make image available in the gallery /* * 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 = FindViewById <ImageView>(Resource.Id.takenPictureImageView); int height = Resources.DisplayMetrics.HeightPixels; int width = imageView.Height; bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); ReplaceDisplay(); // Build our gridview, and assign functions to each button var gridView = FindViewById <GridView>(Resource.Id.gridView); gridView.Adapter = new ImageAdapter(this); gridView.ItemClick += GridView_ItemClick; // Dispose of the Java side bitmap. System.GC.Collect(); }
//Create the remove red button private void NoRed(object sender, System.EventArgs e) { 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(); }
private void HighContrast(ImageView imageoutput) { Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)imageoutput.Drawable; Android.Graphics.Bitmap bitmap = bd.Bitmap; if (bitmap != null) { Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.R = (byte)(ContrastPixelValue(c.R)); c.G = (byte)(ContrastPixelValue(c.G)); c.B = (byte)(ContrastPixelValue(c.B)); copyBitmap.SetPixel(i, j, c); } } if (copyBitmap != null) { imageoutput.SetImageBitmap(copyBitmap); bitmap = null; copyBitmap = null; } System.GC.Collect(); } }
// <summary> // Called automatically whenever an activity finishes // </summary> // <param name = "requestCode" ></ param > // < param name="resultCode"></param> /// <param name="data"></param> protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); //Make image available in the gallery /* * 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 = FindViewById <ImageView>(Resource.Id.takenPictureImageView); int height = Resources.DisplayMetrics.HeightPixels; int width = imageView.Height; if (bitmap != null) { //AC: workaround for not passing actual files //bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); //copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); //AddRandomNoise(); //HighContrast(); //TempHolder(); //TempHolder2(); } bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); if (bitmap != null) { copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); } if (copyBitmap != null) { imageView.SetImageBitmap(copyBitmap); imageView.Visibility = Android.Views.ViewStates.Visible; bitmap = null; copyBitmap = null; } var gridView = FindViewById <GridView>(Resource.Id.gridView); gridView.Adapter = new ImageAdapter(this); gridView.ItemClick += GridView_ItemClick; // Dispose of the Java side bitmap. System.GC.Collect(); }
// <summary> // Called automatically whenever an activity finishes // </summary> // <param name = "requestCode" ></ param > // < param name="resultCode"></param> /// <param name="data"></param> protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); //Make image available in the gallery /* * 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; //AC: workaround for not passing actual files Android.Graphics.Bitmap bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); //Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height); Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Alpha8, 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); //TODO: fix //c.R = 0; copyBitmap.SetPixel(i, j, c); } } if (bitmap != null) { imageView.SetImageBitmap(bitmap); imageView.Visibility = Android.Views.ViewStates.Visible; bitmap = null; } // Dispose of the Java side bitmap. System.GC.Collect(); }
public override VectorElement BuildClusterElement(MapPos pos, VectorElementVector elements) { MarkerStyle style = null; // Try to reuse existing marker styles if (markerStyles.ContainsKey(elements.Count)) { style = markerStyles[elements.Count]; } if (elements.Count == 1) { style = (elements[0] as Marker).Style; } if (style == null) { Android.Graphics.Bitmap canvasBitmap = markerBitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); Android.Graphics.Canvas canvas = new Android.Graphics.Canvas(canvasBitmap); Android.Graphics.Paint paint = new Android.Graphics.Paint(Android.Graphics.PaintFlags.AntiAlias); paint.TextAlign = (Android.Graphics.Paint.Align.Center); paint.TextSize = 12; paint.Color = Android.Graphics.Color.Argb(255, 0, 0, 0); float x = markerBitmap.Width / 2; float y = markerBitmap.Height / 2 - 5; canvas.DrawText(elements.Count.ToString(), x, y, paint); MarkerStyleBuilder styleBuilder = new MarkerStyleBuilder(); styleBuilder.Bitmap = BitmapUtils.CreateBitmapFromAndroidBitmap(canvasBitmap); styleBuilder.Size = 30; styleBuilder.PlacementPriority = -elements.Count; style = styleBuilder.BuildStyle(); markerStyles.Add(elements.Count, style); } // Create marker for the cluster Marker marker = new Marker(pos, style); return(marker); }
private void RandomNoise(ImageView imageoutput) { Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)imageoutput.Drawable; Android.Graphics.Bitmap bitmap = bd.Bitmap; System.Random rnd = new Random(); if (bitmap != null) { Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int noise = rnd.Next(-7, 7); int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); // int red = c.R + noise; // int green = c.G + noise; // int blue = c.B + noise; c.R = (byte)(AdjustPixelValue(c.R + noise)); c.G = (byte)(AdjustPixelValue(c.G + noise)); c.B = (byte)(AdjustPixelValue(c.B + noise)); copyBitmap.SetPixel(i, j, c); } } if (copyBitmap != null) { imageoutput.SetImageBitmap(copyBitmap); bitmap = null; copyBitmap = null; } System.GC.Collect(); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { Android.Graphics.Bitmap bitmap = bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); Android.Graphics.Bitmap copyBitmap = null; bool original_pic = true; ImageView imageView = null; base.OnActivityResult(requestCode, resultCode, data); 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 = FindViewById <ImageView>(Resource.Id.takenPicture); int height = Resources.DisplayMetrics.HeightPixels; int width = height; // width = imageView.Height; //bitmap = _file.Path.LoadAndResizeBitmap(width, height); if (bitmap != null) { SetContentView(Resource.Layout.layout1); imageView = FindViewById <ImageView>(Resource.Id.takenPicture); copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); imageView.SetImageBitmap(bitmap); } else { //SetContentView(Resource.Layout.Main); if (IsThereAnAppToTakePictures() == true) { CreateDirectoryForPictures(); FindViewById <Button>(Resource.Id.launchCamera).Click += TakePicture; } } Button RemoveRed = FindViewById <Button>(Resource.Id.removeRed); Button RemoveGreen = FindViewById <Button>(Resource.Id.removeGreen); Button RemoveBlue = FindViewById <Button>(Resource.Id.removeBlue); Button NegateRed = FindViewById <Button>(Resource.Id.NegateRed); Button NegateGreen = FindViewById <Button>(Resource.Id.NegateGreen); Button NegateBlue = FindViewById <Button>(Resource.Id.NegateBlue); Button GreyScale = FindViewById <Button>(Resource.Id.GreyScale); Button HighContrast = FindViewById <Button>(Resource.Id.HighContrast); Button WoodGrain = FindViewById <Button>(Resource.Id.Woodgrain); Button NewPicture = FindViewById <Button>(Resource.Id.NewPicture); Button Clear = FindViewById <Button>(Resource.Id.Clear); // check bitmap to see if it is null if (copyBitmap != null) { RemoveRed.Click += delegate { for (int i = 0; i < copyBitmap.Width; i++) { for (int j = 0; j < copyBitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.R = 0; copyBitmap.SetPixel(i, j, c); } } imageView.SetImageBitmap(copyBitmap); original_pic = false; }; RemoveGreen.Click += delegate { for (int i = 0; i < copyBitmap.Width; i++) { for (int j = 0; j < copyBitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.G = 0; copyBitmap.SetPixel(i, j, c); } } imageView.SetImageBitmap(copyBitmap); original_pic = false; }; RemoveBlue.Click += delegate { for (int i = 0; i < copyBitmap.Width; i++) { for (int j = 0; j < copyBitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.R = 0; copyBitmap.SetPixel(i, j, c); } } imageView.SetImageBitmap(copyBitmap); original_pic = false; }; NegateRed.Click += delegate { for (int i = 0; i < copyBitmap.Width; i++) { for (int j = 0; j < copyBitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.R = (byte)(255 - c.R); copyBitmap.SetPixel(i, j, c); } } imageView.SetImageBitmap(copyBitmap); original_pic = false; }; NegateGreen.Click += delegate { for (int i = 0; i < copyBitmap.Width; i++) { for (int j = 0; j < copyBitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.G = (byte)(255 - c.G); copyBitmap.SetPixel(i, j, c); } } imageView.SetImageBitmap(copyBitmap); original_pic = false; }; NegateBlue.Click += delegate { for (int i = 0; i < copyBitmap.Width; i++) { for (int j = 0; j < copyBitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.B = (byte)(255 - c.B); copyBitmap.SetPixel(i, j, c); } } imageView.SetImageBitmap(copyBitmap); original_pic = false; }; 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); original_pic = false; }; HighContrast.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); original_pic = false; }; WoodGrain.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); Random r = new Random(); int randnum = r.Next(-20, 21); int r_temp = c.R; int g_temp = c.G; int b_temp = c.B; r_temp = r_temp + randnum; g_temp = g_temp + randnum; b_temp = b_temp + randnum; if (r_temp > 255) { c.R = 255; } else if (r_temp < 0) { c.R = 0; } else { c.R = Convert.ToByte(r_temp); } if (g_temp > 255) { c.G = 255; } else if (g_temp < 0) { c.G = 0; } else { c.G = Convert.ToByte(g_temp); } if (b_temp > 255) { c.B = 255; } else if (b_temp < 0) { c.B = 0; } else { c.B = Convert.ToByte(b_temp); } copyBitmap.SetPixel(i, j, c); } } imageView.SetImageBitmap(copyBitmap); original_pic = false; }; NewPicture.Click += delegate { SetContentView(Resource.Layout.Main); if (IsThereAnAppToTakePictures() == true) { CreateDirectoryForPictures(); FindViewById <Button>(Resource.Id.launchCamera).Click += TakePicture; } }; Clear.Click += delegate { if (original_pic == false) { copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); imageView.SetImageBitmap(copyBitmap); original_pic = true; } else if (original_pic) { Toast.MakeText(this, "No Effects Used", ToastLength.Short).Show(); } }; } }
// <summary> // Called automatically whenever an activity finishes // </summary> // <param name = "requestCode" ></ param > // < param name="resultCode"></param> // <param name="data"> </param> protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); //Make image available in the gallery /* * 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; Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height); // AC: workaround for not passing actual files //Android.Graphics.Bitmap bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); // removes all red from the picture for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.R = 0; copyBitmap.SetPixel(i, j, c); } } if (copyBitmap != null) { imageView.SetImageBitmap(copyBitmap); imageView.Visibility = Android.Views.ViewStates.Visible; bitmap = null; copyBitmap = null; } // removes all blue from the picture for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.B = 0; copyBitmap.SetPixel(i, j, c); } } if (copyBitmap != null) { imageView.SetImageBitmap(copyBitmap); imageView.Visibility = Android.Views.ViewStates.Visible; bitmap = null; copyBitmap = null; } // removes all green from the picture for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.G = 0; copyBitmap.SetPixel(i, j, c); } } if (copyBitmap != null) { imageView.SetImageBitmap(copyBitmap); imageView.Visibility = Android.Views.ViewStates.Visible; bitmap = null; copyBitmap = null; } // changes all the colors in the picture to high contrast for (int i = 0; i < bitmap.Height; i++) { for (int j = 0; j < bitmap.Width; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); int red_pixel = c.R; int green_pixel = c.B; int blue_pixel = c.G; if (red_pixel > (255 / 2) || green_pixel > (255 / 2) || blue_pixel > (255 / 2)) { int r = bitmap.GetPixel(i, j); c.R = 255; c.G = 255; c.B = 255; } else { int s = bitmap.GetPixel(i, j); c.R = 0; c.G = 0; c.B = 0; } } } // changes all the colors in the picture to grayscale for (int i = 0; i < bitmap.Height; i++) { for (int j = 0; j < bitmap.Width; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); int red_pixel = c.R; int green_pixel = c.G; int blue_pixel = c.B; red_pixel = (red_pixel + green_pixel + blue_pixel) / 3; green_pixel = (red_pixel + green_pixel + blue_pixel) / 3; blue_pixel = (red_pixel + green_pixel + blue_pixel) / 3; } } // adds random noise to all of the colors in the pictures /* for(int i = 0; i < bitmap.Height; i++) * { * for(int j = 0; j < bitmap.Width; j++) * { * int random_pixel = rand % 21 + -10; * int random_red = 0, random_green = 0, random_blue = 0; * } * } */ // Dispose of the Java side bitmap System.GC.Collect(); }
private void Blur() // { //Toast.MakeText(this.ApplicationContext, "Method Blur() has been called.", ToastLength.Short).Show(); //this code blurs each pixel with it's immediate neighbors (L & R, U & D), 1 time(s) Android.Graphics.Bitmap prevBitmap; for (int blurCount = 0; blurCount < 1; blurCount++) { prevBitmap = copyBitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { //fetch our pixel int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); if (i == 0) // we're at left border, fetch only right pixel { int r = bitmap.GetPixel(i + 1, j); Android.Graphics.Color cR = new Android.Graphics.Color(r); Android.Graphics.Color[] cr = new Android.Graphics.Color[] { c, cR }; c = BlurHelper(cr); } else if (i == bitmap.Width - 1) // we're at right border, fetch only left pixel { int l = bitmap.GetPixel(i - 1, j); Android.Graphics.Color cL = new Android.Graphics.Color(l); Android.Graphics.Color[] lc = new Android.Graphics.Color[] { cL, c }; c = BlurHelper(lc); } else // otherwise, fetch both left and right pixels { int l = bitmap.GetPixel(i - 1, j); Android.Graphics.Color cL = new Android.Graphics.Color(l); int r = bitmap.GetPixel(i + 1, j); Android.Graphics.Color cR = new Android.Graphics.Color(r); Android.Graphics.Color[] lcr = new Android.Graphics.Color[] { cL, c, cR }; c = BlurHelper(lcr); } if (j == 0) // we're at top border, fetch only down pixel { int d = bitmap.GetPixel(i, j + 1); Android.Graphics.Color cD = new Android.Graphics.Color(d); Android.Graphics.Color[] cd = new Android.Graphics.Color[] { c, cD }; c = BlurHelper(cd); } else if (j == bitmap.Height - 1) // we're at bottom border, fetch only up pixel { int u = bitmap.GetPixel(i, j - 1); Android.Graphics.Color cU = new Android.Graphics.Color(u); Android.Graphics.Color[] uc = new Android.Graphics.Color[] { cU, c }; c = BlurHelper(uc); } else // otherwise, fetch both up and down pixels { int u = bitmap.GetPixel(i, j - 1); Android.Graphics.Color cU = new Android.Graphics.Color(u); int d = bitmap.GetPixel(i, j + 1); Android.Graphics.Color cD = new Android.Graphics.Color(d); Android.Graphics.Color[] ucd = new Android.Graphics.Color[] { cU, c, cD }; c = BlurHelper(ucd); } copyBitmap.SetPixel(i, j, c); } } } }
private void GridView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); if (e.Position == 0) // "ADD RED" { AddRed(); } else if (e.Position == 1) // "ADD GREEN" { AddGreen(); } else if (e.Position == 2) // "ADD BLUE" { AddBlue(); } else if (e.Position == 3) // "TINT" { Tint(); } else if (e.Position == 4) // "ADD RANDOM NOISE" { AddRandomNoise(); } else if (e.Position == 5) // "REMOVE RED" { RemoveRed(); } else if (e.Position == 6) // "REMOVE GREEN" { RemoveGreen(); } else if (e.Position == 7) // "REMOVE BLUE" { RemoveBlue(); } else if (e.Position == 8) // "GRAYSCALE" { Grayscale(); } else if (e.Position == 9) // "BLUR" { Blur(); } else if (e.Position == 10) // "NEGATE RED" { NegateRed(); } else if (e.Position == 11) // "NEGATE GREEN" { NegateGreen(); } else if (e.Position == 12) // "NEGATE BLUE" { NegateBlue(); } else if (e.Position == 13) // "HIGH CONTRAST" { HighContrast(); } else if (e.Position == 14) // "PIXELATE" { Pixelate(); } else if (e.Position == 15) // "FLIP HORIZONTALLY" { FlipHorizontally(); } else if (e.Position == 16) // "FLIP VERTICALLY" { FlipVertically(); } else if (e.Position == 17) // "ROTATE 90 DEGREES" { Rotate90(); } else if (e.Position == 18) // "REVERT" { Toast.MakeText(this.ApplicationContext, "Image reset.", ToastLength.Short).Show(); } else if (e.Position == 19) // "WOODGRAIN EFFECT" { Woodgrain(); } else // Error { // The grid item clicked does not match one of the 20 initialized: {0-19} Toast.MakeText(this.ApplicationContext, "AN ERROR HAS OCCURED.", ToastLength.Short).Show(); } ReplaceDisplay(); }
// <summary> // Called automatically whenever an activity finishes // </summary> // <param name = "requestCode" ></ param > // < param name="resultCode"></param> // <param name="data"></param> protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); //Make image available in the gallery Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); var contentUri = Android.Net.Uri.FromFile(_file); //Uri uri = contentUri.Data; 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; //AC: workaround for not passing actual files Android.Graphics.Bitmap bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); //Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height); //this code removes all red from a picture /*for (int i = 0; i < bitmap.Width; i++) * { * for (int j = 0; j < bitmap.Height; j++) * { * int p = bitmap.GetPixel(i, j); * Android.Graphics.Color c = new Android.Graphics.Color(p); * c.R = 0; * copyBitmap.SetPixel(i, j, c); * } * }*/ if (bitmap != null) { /*Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); * Android.Graphics.Bitmap OGBitmap = copyBitmap;*/ Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); imageView.SetImageBitmap(copyBitmap); imageView.Visibility = Android.Views.ViewStates.Visible; //allows user to see the hidden buttons for effects now Button negRed = FindViewById <Button>(Resource.Id.negatered); Button negGre = FindViewById <Button>(Resource.Id.negategreen); Button negBlu = FindViewById <Button>(Resource.Id.negateblue); Button remGre = FindViewById <Button>(Resource.Id.removegreen); Button highCon = FindViewById <Button>(Resource.Id.highcontrast); Button graSca = FindViewById <Button>(Resource.Id.greyscale); Button remRed = FindViewById <Button>(Resource.Id.removered); Button remBlu = FindViewById <Button>(Resource.Id.removeblue); negRed.Visibility = Android.Views.ViewStates.Visible; negGre.Visibility = Android.Views.ViewStates.Visible; negBlu.Visibility = Android.Views.ViewStates.Visible; remGre.Visibility = Android.Views.ViewStates.Visible; highCon.Visibility = Android.Views.ViewStates.Visible; graSca.Visibility = Android.Views.ViewStates.Visible; remRed.Visibility = Android.Views.ViewStates.Visible; remBlu.Visibility = Android.Views.ViewStates.Visible; //Negate red effect negRed.Click += delegate { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.R = (byte)(255 - c.R); copyBitmap.SetPixel(i, j, c); imageView.SetImageBitmap(copyBitmap); } } }; //Negate green effect negGre.Click += delegate { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.G = (byte)(255 - c.G); copyBitmap.SetPixel(i, j, c); imageView.SetImageBitmap(copyBitmap); } } }; //Negate blue effect negBlu.Click += delegate { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.B = (byte)(255 - c.B); copyBitmap.SetPixel(i, j, c); imageView.SetImageBitmap(copyBitmap); } } }; //Grayscale effect graSca.Click += delegate { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); int r = c.R; int b = c.B; int g = c.G; c.R = (byte)((r + b + g) / 3); c.B = (byte)((r + b + g) / 3); c.G = (byte)((r + b + g) / 3); copyBitmap.SetPixel(i, j, c); imageView.SetImageBitmap(copyBitmap); } } }; //Remove Red effect remRed.Click += delegate { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.R = 0; copyBitmap.SetPixel(i, j, c); imageView.SetImageBitmap(copyBitmap); } } }; //Remove Blue effect remBlu.Click += delegate { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.B = 0; copyBitmap.SetPixel(i, j, c); imageView.SetImageBitmap(copyBitmap); } } }; //Remove Green effect remGre.Click += delegate { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.G = 0; copyBitmap.SetPixel(i, j, c); imageView.SetImageBitmap(copyBitmap); } } }; //High Contrast effect highCon.Click += delegate { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); if (c.R > 177) { c.R = 255; } else { c.R = 0; } if (c.G > 177) { c.G = 255; } else { c.G = 0; } if (c.B > 177) { c.B = 255; } else { c.B = 0; } copyBitmap.SetPixel(i, j, c); imageView.SetImageBitmap(copyBitmap); } } }; } // Dispose of the Java side bitmap. System.GC.Collect(); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 1) { if (resultCode == Result.Ok) { var imageView = FindViewById <ImageView>(Resource.Id.imageoutput); imageView.SetImageURI(data.Data); Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)imageView.Drawable; Android.Graphics.Bitmap bitmap = bd.Bitmap; //Gotta shrink down the bitmaps because they tend to be too big int height = bitmap.Height; int width = bitmap.Width; ScaleBounds(ref height, ref width); Android.Graphics.Bitmap smallBitmap = Android.Graphics.Bitmap.CreateScaledBitmap(bitmap, width, height, true); imageView.SetImageBitmap(smallBitmap); mainbp = smallBitmap; imageView.Visibility = Android.Views.ViewStates.Visible; } } else if (requestCode == 0) { if (resultCode == Result.Ok) { ImageView imageView = FindViewById <ImageView>(Resource.Id.imageoutput); int height = Resources.DisplayMetrics.HeightPixels; int width = imageView.Height; //AC: workaround for not passing actual files Android.Graphics.Bitmap bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data"); Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); if (copyBitmap != null) { imageView.SetImageBitmap(copyBitmap); mainbp = copyBitmap; imageView.Visibility = Android.Views.ViewStates.Visible; bitmap = null; copyBitmap = null; } // Dispose of the Java side bitmap. System.GC.Collect(); } } }
private void NegateColor(char color, ImageView imageoutput) { //Weird hoops you gotta go through to get some bitmaps :/ Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)imageoutput.Drawable; Android.Graphics.Bitmap bitmap = bd.Bitmap; Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); if (bitmap != null) { switch (color) { case 'r': { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.R = (byte)(255 - c.R); copyBitmap.SetPixel(i, j, c); } } break; } case 'g': { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.G = (byte)(255 - c.G); copyBitmap.SetPixel(i, j, c); } } break; } case 'b': { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int p = bitmap.GetPixel(i, j); Android.Graphics.Color c = new Android.Graphics.Color(p); c.B = (byte)(255 - c.B); copyBitmap.SetPixel(i, j, c); } } break; } default: { break; } } if (copyBitmap != null) { imageoutput.SetImageBitmap(copyBitmap); bitmap = null; copyBitmap = null; } System.GC.Collect(); } }