关于改变Bitmap透明度

来源:互联网 发布:淘宝网斜挎女包 编辑:程序博客网 时间:2024/05/16 10:14
/** 透明度为 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;
}
0 0
原创粉丝点击