Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] java – Turning a Double into color ints in Android Studio

Posted on November 14, 2022

Solution 1 :

A quick way to map a value to a color by using one of the methods in Color class.

For example, using Color.HSVToColor and passing your value in as the “hue” will give you a rainbow color palette. The appropriate mapping will depend on what range the values in your matrix can take. If they are in the range -1 to +1, this will work for you:

float hue = (float) (matrix[i][j] + 1) * 180;
float[] hsv = { hue, 1f, 1f };
int color = Color.HSVToColor(hsv);

Problem :

I’m working with an image in android studio. To make it simple let’s say it only has 9 pixels. The values of the pixel are held in a double matrix in, lets say its something I like this:

double[][] matrix = {{-0.5, -0.4, -0.3},
                     {-0.1, -0.9, -0.4},
                     {-0.5, -0.6, -0.9}}

I want to turn each of those doubles into a color int so I can put them into an image pixel by pixel. (In Matlab you’d use something like colormap('jet')).

Bitmap bitmap = Bitmap.createBitmap(length, height, Bitmap.Config.RGB_565);
                for(int i = 0; i< length ; i++ ){
                    for (int j = 0; j < height; j++){
                        //Convert number in matrix to color from blue to red
                        int color;

                        //Make correlating pixel that color
                        bitmap.setPixel(i,j, color);
                    }
                }

I have tried using the Scichart SDK but the license is too expensive.
I also tried the Mines package but it depends on Java AWT which is not available in android studio

I can’t find anything on the documentation.

Comments

Comment posted by Lennart Steinke

You need to convert the color values from the input format to the output format. The output format is RGB, with 1 byte for R, G and B. In what format are your input values?

READ  [ANSWERED] android - Common searchview for all fragments of tab layout or bottom navigation view?
Powered by Inline Related Posts

Comment posted by Alext.45

My input values are just doubles.

Comment posted by Lennart Steinke

yes, but what do the values represent? YUV? RGB? HSV? In what ranges?In order to make a meaningful conversion, you need to know what these values represent.

Comment posted by Alext.45

This is a good start. What do I do if my values are in a much closer range? When I tried running that I got the same color for every pixel.

Comment posted by Joni

Then you need to find a way to map the range where they are to the range expected by the color function. For the hue component of HSVToColor, the range is 0 to 360.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress