|
5 | 5 | import android.graphics.BitmapFactory; |
6 | 6 | import android.graphics.BitmapShader; |
7 | 7 | import android.graphics.Canvas; |
| 8 | +import android.graphics.Color; |
8 | 9 | import android.graphics.ColorMatrix; |
9 | 10 | import android.graphics.ColorMatrixColorFilter; |
10 | 11 | import android.graphics.Paint; |
|
14 | 15 | import android.graphics.RectF; |
15 | 16 | import android.graphics.Shader; |
16 | 17 | import android.os.Build; |
| 18 | +import android.view.Gravity; |
17 | 19 | import android.view.View; |
18 | 20 |
|
| 21 | +import com.moioio.android.g2d.Graphics; |
| 22 | + |
19 | 23 | public class BitmapUtil { |
20 | 24 |
|
21 | 25 | public static final Bitmap bitmapToGary(Bitmap bitmap) { |
@@ -110,6 +114,34 @@ public static Bitmap getScaleBitmap(Bitmap bitmap,int w,int h) { |
110 | 114 | return bmp; |
111 | 115 | } |
112 | 116 |
|
| 117 | + public static Bitmap changeBitmapColor(Bitmap bitmap,int color) { |
| 118 | + |
| 119 | + int r = Color.red(color); |
| 120 | + int g = Color.green(color); |
| 121 | + int b = Color.blue(color); |
| 122 | + int a = Color.alpha(color); |
| 123 | + |
| 124 | + float[] colorTransform = { |
| 125 | + 1, 0f, 0, 0, r, |
| 126 | + 0, 1, 0f, 0, g, |
| 127 | + 0, 0, 1, 0f, b, |
| 128 | + 0, 0, 0, 1f, a}; |
| 129 | + |
| 130 | + ColorMatrix colorMatrix = new ColorMatrix(); |
| 131 | + colorMatrix.set(colorTransform); //Apply the Red |
| 132 | + |
| 133 | + ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix); |
| 134 | + |
| 135 | + Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); |
| 136 | + Canvas canvas = new Canvas(newBitmap); |
| 137 | + Graphics grap = new Graphics(canvas); |
| 138 | + grap.setColorFilter(colorFilter); |
| 139 | + grap.drawImage(bitmap,0,0); |
| 140 | + |
| 141 | + |
| 142 | + return newBitmap; |
| 143 | + } |
| 144 | + |
113 | 145 |
|
114 | 146 | public static Bitmap getBitmapByCanvas(View view) { |
115 | 147 | Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); |
|
0 commit comments