java - how to extract red, green and blue channels of bitmap in Android -


i have bitmap image loaded memory bitmap object. can load imageview,do operations using canvas , forth.but algorithm i'm using need 3 channel grey scale bitmaps. below image article written eric z goodnight on how geek.the link given below.

https://www.howtogeek.com/howto/42393/rgb-cmyk-alpha-what-are-image-channels-and-what-do-they-mean/

enter image description here can see in grey scale images corresponding each channels respective colour areas brightest. how can extract grey scale images corresponding each channels bitmap image in android? require 3 bitmaps objects containing these 3 channel grey scales respectively.i have come across method create grey scale setting saturation of colormatrix 0.but returns on 1 grey scale.is there way grey scale images corresponding 3 channels?

a pixel in bitmap format represented 4 bytes integer, describe alpha, red, green , blue channels of pixel. extracting particular channel, can bitwise or on every pixel, appropriate hex value.

for instance, 0xffff0000 represents max alpha (ff), max red (ff), 0 green , 0 blue. bitwise or every pixel, result in green , blue channels ignored, cause 0 (00).

anyway, code might below extracting red channel :

for (int x = 0; x < bitmap.getwidth(); x++)  {     (int y = 0; y < bitmap.getheight(); y++)     {        bitmap.setpixel(x, y, bitmap.getpixel(x, y) & 0xffff0000);    } } 

consequently, green channel can obtained :

 (int x = 0; x < bitmap.getwidth(); x++)  {     (int y = 0; y < bitmap.getheight(); y++)     {        bitmap.setpixel(x, y, bitmap.getpixel(x, y) & 0xff00ff00);    } } 

and blue channel :

for (int x = 0; x < bitmap.getwidth(); x++)  {     (int y = 0; y < bitmap.getheight(); y++)     {        bitmap.setpixel(x, y, bitmap.getpixel(x, y) & 0xff0000ff);    } } 

finally, display image in grayscale can use colormatrix imageview widget :

    colormatrix matrix = new colormatrix();     matrix.setsaturation(0);      colormatrixcolorfilter filter = new colormatrixcolorfilter(matrix);     imageview.setcolorfilter(filter); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -