Adjust the color of a drawable
private Drawable adjust(Drawable drawableToAdjust,int colorAdjust)
{
int pixelFrom,pixelTo;
Bitmap src = ((BitmapDrawable) drawableToAdjust).getBitmap();
Bitmap bitmap = src.copy(Bitmap.Config.ARGB_8888, true);
for(int x = 0;x < bitmap.getWidth();x++)
for(int y = 0;y < bitmap.getHeight();y++)
{
pixelFrom=bitmap.getPixel(x, y);
pixelTo=Color.argb(
(int)( (double)Color.alpha(pixelFrom)*Color.alpha(colorAdjust)/255),
(int)(255-((double)Color.red (pixelFrom)*(1-(double)Color.red (colorAdjust)/255))),
(int)(255-((double)Color.green(pixelFrom)*(1-(double)Color.green(colorAdjust)/255))),
(int)(255-((double)Color.blue (pixelFrom)*(1-(double)Color.blue (colorAdjust)/255)))
);
bitmap.setPixel(x,y,pixelTo);
}
return new BitmapDrawable(bitmap);
}
{
int pixelFrom,pixelTo;
Bitmap src = ((BitmapDrawable) drawableToAdjust).getBitmap();
Bitmap bitmap = src.copy(Bitmap.Config.ARGB_8888, true);
for(int x = 0;x < bitmap.getWidth();x++)
for(int y = 0;y < bitmap.getHeight();y++)
{
pixelFrom=bitmap.getPixel(x, y);
pixelTo=Color.argb(
(int)( (double)Color.alpha(pixelFrom)*Color.alpha(colorAdjust)/255),
(int)(255-((double)Color.red (pixelFrom)*(1-(double)Color.red (colorAdjust)/255))),
(int)(255-((double)Color.green(pixelFrom)*(1-(double)Color.green(colorAdjust)/255))),
(int)(255-((double)Color.blue (pixelFrom)*(1-(double)Color.blue (colorAdjust)/255)))
);
bitmap.setPixel(x,y,pixelTo);
}
return new BitmapDrawable(bitmap);
}
Comments
Post a Comment