您的位置:首页 > 其它

关于改变Bitmap透明度

2015-08-31 11:08 190 查看
/** 透明度为 0 -- 255 */

private Bitmap getAlphaBitmap(Bitmap bmp,int alpha){

Bitmap tempBmp = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888);

int[] oldPixes = new int[bmp.getWidth() * bmp.getHeight()];

int[] newPixes = new int[bmp.getWidth() * bmp.getHeight()];

// getPixels 颜色数组 ,起始偏移量,每行的长度,起始位置的x、y坐标,读取数组的总长度和总高度 该api目的为保存像素到数组中去

bmp.getPixels(oldPixes, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());

int color = 0;

for(int i = 1;i<oldPixes.length; i++){

color = oldPixes[i];

newPixes[i] = Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));

}

tempBmp.setPixels(newPixes, 0, tempBmp.getWidth(), 0, 0, tempBmp.getWidth(), tempBmp.getHeight());

return tempBmp;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: