How to get pixel color in Android?

后端 未结 3 1132
一向
一向 2021-01-23 18:26

I have set a PNG image(image having transparent background) as button background, When I touch the button it shows me X-coordinate and Y-coordinate of the button’s touched posit

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-23 19:16

    First, you can get the Bitmap with the BitmapFactory like this:
    Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);

    Now you have the Bitmap. On this Bitmap, you can call the function getPixel(int x, int y) to get the Color of this Pixel.
    I guess you then can get the alpha from that Color..

    See the following links for further information:

    • Bitmap Example
    • getPixel(..)
    • Android Color

提交回复
热议问题