How can I get photo's pixel colors after take a telephone camera photo's, in kotlin ?
Asked
Active
Viewed 1,063 times
1 Answers
2
I'm guessing this is for android since you mentioned phone's camera.
I'm not sure if you're asking just how to get pixel colors or in general how to have user take photo then you get photo colors from it but to have user choose a picture then follow this Get Image from the Gallery and Show in ImageView and convert to kotlin. If you want user to take picture then follow this example Capture Image from Camera and Display in Activity. After doing that you'll have a bitmap of the photo so to get pixel colors from that you'll want to use
getPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height)
so if you have
val bitmap = ....
val pixels = IntArray(bitmap.width * bitmap,height)
bitmap.getPixels(pixels, 0, 0, 0, 0, bitmap.width, bitmap.height)
and there you have array of colors. you can also just use for specific pixel
val argb = bitmap.getPixel(x, y)

chris
- 86
- 4