现在的位置: 首页 > 综合 > 正文

Android 读取图片的颜色值

2018年05月16日 ⁄ 综合 ⁄ 共 586字 ⁄ 字号 评论关闭

Android SDK中提供了Bitmap图片每个像素颜色读取的方法:

public void getPixColor(){

Bitmap src =  BitmapFactory.decodeResource(getResources(),R.drawable.imgbg);
        int A, R, G, B;
        int pixelColor;
        int height = src.getHeight();
        int width = src.getWidth();

         for (int y = 0; y < height; y++) {
             for (int x = 0; x < width; x++) {
                 pixelColor = src.getPixel(x, y);
                 A = Color.alpha(pixelColor);
                 R = Color.red(pixelColor);
                 G = Color.green(pixelColor);
                 B = Color.blue(pixelColor);
                 
                 Log.e("A:", A+"");
                 Log.e("R:", R+"");
                 Log.e("G:", G+"");
                 Log.e("B:", B+"");

             }
         }

}

抱歉!评论已关闭.