Reputation: 1795
I receive an link to an image that's 8Bit Greyscale. Now I download it and decode it like this
urlLabels = //someurl
val btLabel = BitmapFactory.decodeStream(urlLabels.openStream())
///And I use it like this
labelBitmap = labelBt.copy(Bitmap.Config.ARGB_8888, false) // idk what to use as Bitmap.config
labelPixels = IntArray(labelBitmap.width * labelBitmap.height)
labelBitmap.getPixels(labelPixels, 0, labelBitmap.width, 0, 0, labelBitmap.width, labelBitmap.height)
The values I get from this Bitmap are then -16777216
and similar values, while I need it to be between 0-255 to correspond to some values I receive from my API. I am only starting to work with colors and images so I've been super confused. I tried searching online but 8Bit greyscale config doesn't seem to be a thing? But that's probably me misunderstanding everything. Basically I just want to download the image and be able to read the values of its pixels in correct 8Bit form (values between 0-255).
Edit: Since I am really unfamiliar with this, it probably is missing some key information, so please comment and request more information than I've provided if necessary. And please stay polite and dumb down your answers so I can understand them and implement them, explanations are welcomed as I'd love to understand what is happening.
Upvotes: 1
Views: 342
Reputation: 2708
#FFFFFF (hexadecimal) = 16777215 (decimal) which is the highest number for an RGB.
Executing "Color.valueOf(-16777216)" in Android returns "Color(r:0.0, g:0.0, b:0.0, a:1.0, color_space: sRGB IEC61966-2.1)" which is the BLACK_without_transparency.
To get values between 0 and 255 you have to split the Color in this way:
red: Color.valueOf(-16777216).red()*255
green: Color.valueOf(-16777216).green()*255
blue: Color.valueOf(-16777216).blue()*255
Upvotes: 2