locked
is there a way to find every color value of every pixel in an image RRS feed

  • Question

  • User390299 posted

    im trying to create an adaptable color scheme and I want to get every color value in an image and put it into percentages of certain values so I can have the background create a color scheme for the image that looks satisfying. kinda like what pandora does with album covers

    Wednesday, January 20, 2021 8:44 PM

All replies

  • User371688 posted

    Sorry, I don't quite understand what you mean by words get every color value in an image and put it into percentages of certain values so I can have the background create a color scheme for the image.

    Can you elaborate on that in detail or upload an image of what you want to achieve?Thanks in advance.


    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.

    Thursday, January 21, 2021 9:24 AM
  • User390299 posted

    @jezh every pixle has a color value or some sort so I want to make something that can measure the values and find a custom color scheme as in pandora(photos attatched) see what they did with the album covers

    Thursday, January 21, 2021 11:29 AM
  • User371688 posted

    In android, you can get the pixel from the view like this:

    ImageView imageView = ((ImageView)v);
    Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
    int pixel = bitmap.getPixel(x,y);
    

    Now you can get each channel with:

    int redValue = Color.red(pixel);
    int blueValue = Color.blue(pixel);
    int greenValue = Color.green(pixel);
    

    The Color functions return the value in each channel. So all you have to do is check if Red is 255 and green and blue are 0, than set the textView text to "it is red". Just pay attention that saying that something is red is not simply that the red channel is the greater than zero. 'Cos 255-Green and 255-Red is yellow, of course. You can also just compare the pixel to different color.

    For example:

    if(pixel == Color.MAGENTA){ textView.setText("It is Magenta"); }

    Hope it can help you.

    Friday, January 22, 2021 8:09 AM
  • User390299 posted

    @jezh is there a way to list all the colors in one place such as for every pixel in bitmap give RGB value and list in a scroll view

    Friday, January 22, 2021 2:41 PM
  • User371688 posted

    You can scale the touch X/Y coordinates based on the size of the ImageView and your original drawable/bitmap (intrinsic values), offset the X/Y by the current bounds and that should give you the coordinates of the touch translated to your bitmap .

    You can refer to the following code:

    var drawable = (BitmapDrawable)colorPanel.Drawable; colorPanel.Touch += (object sender, Android.Views.View.TouchEventArgs e) => { var intrinsicScaleX = (float)drawable.IntrinsicWidth / (float)drawable.Bounds.Width(); var intrinsicScaleY = (float)drawable.IntrinsicHeight / (float)drawable.Bounds.Height(); var viewScaleX = (float)drawable.IntrinsicWidth / (float)colorPanel.Width; var viewScaleY = (float)drawable.IntrinsicHeight / (float)colorPanel.Height; var x = (e.Event.GetX() - drawable.Bounds.Left) * intrinsicScaleX * viewScaleX; var y = (e.Event.GetY() - drawable.Bounds.Top) * intrinsicScaleY * viewScaleY; var pixel = drawable.Bitmap.GetPixel((int)x, (int)y); Console.WriteLine($"{viewScaleX}:{viewScaleY}::{e.Event.GetX()}:{e.Event.GetY()}:{x}:{y}:{Color.GetRedComponent(pixel)}:{Color.GetGreenComponent(pixel)}:{Color.GetBlueComponent(pixel)}"); };

    Refer : https://stackoverflow.com/questions/43048834/xamarin-getting-a-wrong-color-from-bitmap

    Tuesday, January 26, 2021 8:26 AM