在android中将位图上的白色转换为透明
我想在android位图中将白色背景转换为透明背景 我的情况: 原始图像:我无法发布图像在android中将位图上的白色转换为透明,android,colors,bitmap,background,transparent,Android,Colors,Bitmap,Background,Transparent,我想在android位图中将白色背景转换为透明背景 我的情况: 原始图像:我无法发布图像 public Bitmap replaceColor(Bitmap src){ if(src == null) return null; int width = src.getWidth(); int height = src.getHeight(); int[] pixels = new int[width * height]; src.getPix
public Bitmap replaceColor(Bitmap src){
if(src == null)
return null;
int width = src.getWidth();
int height = src.getHeight();
int[] pixels = new int[width * height];
src.getPixels(pixels, 0, width, 0, 0, width, height);
for(int x = 0;x < pixels.length;++x){
pixels[x] = ~(pixels[x] << 8 & 0xFF000000) & Color.BLACK;
}
Bitmap result = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
return result;
}
公共位图替换颜色(位图src){
如果(src==null)
返回null;
int width=src.getWidth();
int height=src.getHeight();
int[]像素=新int[宽度*高度];
getPixels(像素,0,宽度,0,0,宽度,高度);
用于(int x=0;x公共位图替换颜色(位图src){
如果(src==null)
返回null;
int width=src.getWidth();
int height=src.getHeight();
int[]像素=新int[宽度*高度];
src.getPixels(像素,0,1*宽度,0,0,宽度,高度);
用于(int x=0;x //像素[x]=~(像素[x]这是因为Color.white是FFFFFFFF。但是fffffff e在眼睛看来仍然是白色的,但不会被此算法捕获。该算法只适用于精心制作的图像。谢谢您的评论。我不明白您的意思….?所以,我无法解决此问题?VVB,您的解决方案不适用于我的情况,因为我不使用X如果你知道其他的解决方案,请写信给这里。
if (pixels[x] == Color.white)
public Bitmap replaceColor(Bitmap src){
if(src == null)
return null;
int width = src.getWidth();
int height = src.getHeight();
int[] pixels = new int[width * height];
src.getPixels(pixels, 0, width, 0, 0, width, height);
for(int x = 0;x < pixels.length;++x){
if(pixels[x] == Color.WHITE){
pixels[x] = ~(pixels[x] << 8 & 0xFF000000) & Color.BLACK;
}
}
Bitmap result = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
return result;
}
public Bitmap replaceColor(Bitmap src) {
if (src == null)
return null;
int width = src.getWidth();
int height = src.getHeight();
int[] pixels = new int[width * height];
src.getPixels(pixels, 0, 1 * width, 0, 0, width, height);
for (int x = 0; x < pixels.length; ++x) {
// pixels[x] = ~(pixels[x] << 8 & 0xFF000000) & Color.BLACK;
if(pixels[x] == Color.WHITE) pixels[x] = 0;
}
return Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
}