Captured Image to Another Activity

I am having trouble on how to pass the capture image on another activity. I want the captured image to be process on sobel edge detection and display it on the another layout or imageview. Can you please help me? Thanks in advance.

`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using Environment = Android.OS.Environment;
using Uri = Android.Net.Uri;
using Java.IO;
using Android.Provider;
using Android.Content.PM;
using Android.Content.Res;

namespace FinalSDA
{
public static class App
{
public static File _file;
public static File _dir;
}

[Activity(Label = "Camera", ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
public class Camera : Activity
{
    //Intent code for camera activity
    private static int TAKE_PICTURE_CODE = 1;

    //Bitmap of a picture taken
    private Bitmap cameraBitmap = null;


    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        openCamera();
        /*if (IsThereAnAppToTakePictures())
        {
            CreateDirectoryForPictures();
            openCamera();
        }*/
    }

    private void openCamera()
    {
        //camera intent with ACTION_IMAGE_CAPTURE action
        Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
        //App._file = new File(App._dir, String.Format("skindisease_{0}.jpg", Guid.NewGuid()));
        //intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(App._file));

        //start camera activity
        StartActivityForResult(intent, TAKE_PICTURE_CODE);
    }

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
    {
        base.OnActivityResult(requestCode, resultCode, intent);


        //check if method return takepicturecode
        if (requestCode == TAKE_PICTURE_CODE && Intent != null)
        {
            Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
            Uri contentUri = Uri.FromFile(App._file);
            mediaScanIntent.PutExtra("ImageUri", contentUri);
            processImage();
        }

    }

    private void processImage()
    {
        SetContentView(Resource.Layout.Result);
        Uri fullFilePath = (Uri)Intent.GetParcelableExtra("ImageUri");
        ImageView image_view = FindViewById<ImageView> (Resource.Id.image_view);

        Sobel(fullFilePath);
    }
    private void Sobel(Uri fullFilePath)
    {

        if (null != cameraBitmap)
        {

            int[,] Gx = new int[3, 3]{ {-1, 0, 1 }, 
                                   {-2, 0, 2 } , 
                                   {-1, 0, 1 } };

            int[,] Gy = new int[3, 3]{ {-1,-2,-1}, 
                                   { 0, 0, 0 }, 
                                   { 1, 2, 1}};

            int[,] TotalGx = new int[cameraBitmap.Width, cameraBitmap.Height];
            int[,] TotalGy = new int[cameraBitmap.Width, cameraBitmap.Height];
            int[,] GTotal = new int[cameraBitmap.Width, cameraBitmap.Height];

            Bitmap.Config config = Bitmap.Config.Argb8888;
            Bitmap bitmap2 = Bitmap.CreateBitmap(cameraBitmap.Width, cameraBitmap.Height, config);

            for (int i = 1; i < cameraBitmap.Width - 1; i++)
            {
                for (int j = 1; j < cameraBitmap.Height - 1; j++)
                {
                    var colorValueA = cameraBitmap.GetPixel(i - 1, j - 1);//[0][0]
                    var myColorA = Color.GetGreenComponent(colorValueA);
                    //var myColorA = Color.Argb(Color.GetAlphaComponent(colorValueA), Color.GetRedComponent(colorValueA), Color.GetGreenComponent(colorValueA), Color.GetBlueComponent(colorValueA));

                    var colorValueB = cameraBitmap.GetPixel(i - 1, j);//[0][1]
                    var myColorB = Color.GetGreenComponent(colorValueB);
                    //var myColorB = Color.Argb(Color.GetAlphaComponent(colorValueB), Color.GetRedComponent(colorValueB), Color.GetGreenComponent(colorValueB), Color.GetBlueComponent(colorValueB));

                    var colorValueC = cameraBitmap.GetPixel(i - 1, j + 1);//[0][2]
                    var myColorC = Color.GetGreenComponent(colorValueC);
                    //var myColorC = Color.Argb(Color.GetAlphaComponent(colorValueC), Color.GetRedComponent(colorValueC), Color.GetGreenComponent(colorValueC), Color.GetBlueComponent(colorValueC));

                    var colorValueD = cameraBitmap.GetPixel(i, j - 1);//[1][0]
                    var myColorD = Color.GetGreenComponent(colorValueD);
                    //var myColorD = Color.Argb(Color.GetAlphaComponent(colorValueD), Color.GetRedComponent(colorValueD), Color.GetGreenComponent(colorValueD), Color.GetBlueComponent(colorValueD));

                    var colorValueF = cameraBitmap.GetPixel(i, j);//[1][1]
                    var myColorF = Color.GetGreenComponent(colorValueF);
                    //var myColorF = Color.Argb(Color.GetAlphaComponent(colorValueF), Color.GetRedComponent(colorValueF), Color.GetGreenComponent(colorValueF), Color.GetBlueComponent(colorValueF));

                    var colorValueG = cameraBitmap.GetPixel(i, j + 1);//[1][2]
                    var myColorG = Color.GetGreenComponent(colorValueG);
                    //var myColorG = Color.Argb(Color.GetAlphaComponent(colorValueG), Color.GetRedComponent(colorValueG), Color.GetGreenComponent(colorValueG), Color.GetBlueComponent(colorValueG));

                    var colorValueH = cameraBitmap.GetPixel(i + 1, j - 1);//[2][0]
                    var myColorH = Color.GetGreenComponent(colorValueH);
                    //var myColorH = Color.Argb(Color.GetAlphaComponent(colorValueH), Color.GetRedComponent(colorValueH), Color.GetGreenComponent(colorValueH), Color.GetBlueComponent(colorValueH));

                    var colorValueL = cameraBitmap.GetPixel(i + 1, j);//[2][1]
                    var myColorL = Color.GetGreenComponent(colorValueL);
                    //var myColorL = Color.Argb(Color.GetAlphaComponent(colorValueL), Color.GetRedComponent(colorValueL), Color.GetGreenComponent(colorValueL), Color.GetBlueComponent(colorValueL));

                    var colorValueN = cameraBitmap.GetPixel(i + 1, j + 1);//[2][2]
                    var myColorN = Color.GetGreenComponent(colorValueN);
                    //var myColorN = Color.Argb(Color.GetAlphaComponent(colorValueN), Color.GetRedComponent(colorValueN), Color.GetGreenComponent(colorValueN), Color.GetBlueComponent(colorValueN));

                    TotalGx[i, j] = Gx[0, 0] * myColorA + Gx[0, 1] * myColorB + Gx[0, 2] * myColorC
                                   + Gx[1, 0] * myColorD + Gx[1, 1] * myColorF + Gx[1, 2] * myColorG
                                   + Gx[2, 0] * myColorH + Gx[2, 1] * myColorL + Gx[2, 2] * myColorN;

                    if (TotalGx[i, j] < 0) { TotalGx[i, j] = 0; }
                    if (TotalGx[i, j] > 255) { TotalGx[i, j] = 255; }

                    TotalGy[i, j] = Gy[0, 0] * myColorA + Gy[0, 1] * myColorB + Gy[0, 2] * myColorC
                                  + Gy[1, 0] * myColorD + Gy[1, 1] * myColorF + Gy[1, 2] * myColorG
                                  + Gy[2, 0] * myColorH + Gy[2, 1] * myColorL + Gy[2, 2] * myColorN;

                    if (TotalGy[i, j] < 0) { TotalGy[i, j] = 0; }
                    if (TotalGy[i, j] > 255) { TotalGy[i, j] = 255; }

                }

                for (int k = 1; k < cameraBitmap.Width - 1; k++)
                {
                    for (int j = 1; j < cameraBitmap.Height - 1; j++)
                    {
                        GTotal[k, j] = TotalGx[k, j] + TotalGy[k, j];

                        if (GTotal[k, j] >= 255)
                        { GTotal[k, j] = 255; }

                        if (GTotal[k, j] < 0)
                        { GTotal[k, j] = 0; }

                        bitmap2.SetPixel(k, j, Color.Argb(Color.GetAlphaComponent(GTotal[k, j]), Color.GetRedComponent(GTotal[k, j]), Color.GetGreenComponent(GTotal[k, j]), Color.GetBlueComponent(GTotal[k, j])));
                    }
                }
            }
            ImageView image_view = (ImageView)FindViewById(Resource.Id.image_view);
            image_view.SetImageURI(bitmap2);
        }
    }

}

}`

Answers

Sign In or Register to comment.