需求
最近有个需求要合成证件照片,证件头像是白底的一寸照片,但是用bitmap合成的时候需要透明的头像照片,就需要将照片的白色背景变成透明色。有两种处理方式,推荐使用第一种.
第一种:bitmap是不可编辑的
不可编辑的bitmap意思是从文件或流中decode的。
Bitmap idPortraitTemp = BitmapFactory.decodeFile(portrait);
int portraitWidth = idPortraitTemp.getWidth();
int portraitHeight = idPortraitTemp.getHeight();
int[] argbs = new int[portraitWidth * portraitHeight];
idPortraitTemp.getPixels(argbs, 0, portraitWidth, 0, 0, portraitWidth, p