I need a function that will accept a bitmap and return a bitmap with a changed color. It should be quick and easy.
The goal is to change the color, also this is a png with alpha.
I looked online, but I canβt use canvas or anything external. The function is in an external object (do not ask ..)
Here is what I have had so far (not working). I know that I'm very close, just a matter of sorting the color matrix and getting alpha for the job.
public Bitmap changeBitmapColor(Bitmap sourceBitmap, int deg) { int width, height; height = sourceBitmap.getHeight(); width = sourceBitmap.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint();
Any help would be great!
------- FIXED --------
I fixed this by changing the color matrix, now the bitmap will change color and not display alpha values.
First of all, this is the matrix:
cm.set(new float[] { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 140, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 });
The second thing I had to change is a line of code:
Bitmap newBM = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Good luck readers!