Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Can we grayscale the inbuilt Android camera using Xamarin ?

jayanijayani Member ✭✭

Can we use grayscale feature in the inbuilt Android camera? Are there any Xamarin plugins to do this?



  • YelinzhYelinzh Member, Xamarin Team Xamurai

    Can we use grayscale feature in the inbuilt Android camera?

    It doesn't support to take a grayscale photo directly. We need to get to the image first and then convert it to the grayscale version.

    Check the code:

    Display the imageView and convert the image to grayscale.

    ColorMatrix matrix = new ColorMatrix();
    var img = FindViewById<ImageView>(Resource.Id.img);
    img.SetColorFilter(new ColorMatrixColorFilter(matrix));

    Or get the bitmap of the image and convert it to the grayscale style.

    public Bitmap ConvertToGrayscale(Bitmap _bitmap)
        int width, height;
        height = _bitmap.Height;
        width = _bitmap.Width;
        Bitmap grayscale_bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
        Canvas c = new Canvas(grayscale_bitmap);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        c.DrawBitmap(_bitmap, 0, 0, paint);
        return grayscale_bitmap;

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Sign In or Register to comment.