示例#1
0
  public static Bitmap setTint(Bitmap sourceBitmap, int color) {

    try {

      Bitmap resultBitmap =
          Bitmap.createBitmap(
              sourceBitmap.getWidth(), sourceBitmap.getHeight(), Bitmap.Config.ARGB_8888);

      Canvas canvas = new Canvas(resultBitmap);

      float r = ((color >> 16) & 0xFF) / 255.0f;
      float g = ((color >> 8) & 0xFF) / 255.0f;
      float b = ((color >> 0) & 0xFF) / 255.0f;

      float[] colorTransform = {0, r, 0, 0, 0, 0, 0, g, 0, 0, 0, 0, 0, b, 0, 0, 0, 0, 1f, 0};

      ColorMatrix colorMatrix = new ColorMatrix();
      colorMatrix.setSaturation(0f);
      colorMatrix.set(colorTransform);

      ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
      Paint paint = new Paint();
      paint.setColorFilter(colorFilter);
      canvas.drawBitmap(sourceBitmap, 0, 0, paint);

      return resultBitmap;

    } catch (IllegalArgumentException ex) {
      return null;
    }
  }
示例#2
0
 public ViewHolder setBrightness(int viewId, int brightness) {
   ImageView imageView = (ImageView) getView(viewId);
   ColorMatrix colorMatrix = new ColorMatrix();
   colorMatrix.set(
       new float[] {
         1, 0, 0, 0, brightness, 0, 1, 0, 0, brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0
       });
   imageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
   return this;
 }
示例#3
0
  private void initRendering(int mode) {
    Paint paint = new Paint();

    switch (mode) {
      case 0:
        { // Default
          paint.setColorFilter(null);
          break;
        }
      case 1:
        { // Grayscale
          ColorMatrix matrix = new ColorMatrix();
          matrix.setSaturation(0);
          ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
          paint.setColorFilter(filter);
          break;
        }
      case 2:
        { // Inverted
          ColorMatrixColorFilter filter = new ColorMatrixColorFilter(NEGATIVE_COLOR);
          paint.setColorFilter(filter);
          break;
        }
      case 3:
        { // Inverted grayscale
          ColorMatrix matrix = new ColorMatrix();
          matrix.set(NEGATIVE_COLOR);

          ColorMatrix gcm = new ColorMatrix();
          gcm.setSaturation(0);

          ColorMatrix concat = new ColorMatrix();
          concat.setConcat(matrix, gcm);

          ColorMatrixColorFilter filter = new ColorMatrixColorFilter(concat);
          paint.setColorFilter(filter);

          break;
        }
      default:
        {
          paint.setColorFilter(null);
          break;
        }
    }

    // maybe sometime LAYER_TYPE_NONE would better?
    setLayerType(View.LAYER_TYPE_HARDWARE, paint);
  }
示例#4
0
  public static Bitmap colorMatrixBmp(Bitmap bmp, float[] matrixSrc) {

    int width = bmp.getWidth();
    int height = bmp.getHeight();

    ColorMatrix matrix = new ColorMatrix();
    matrix.set(matrixSrc);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
    Paint p = new Paint();
    p.setColorFilter(filter);
    Bitmap colorBmp = Bitmap.createBitmap(width, height, bmp.getConfig());
    Canvas c = new Canvas(colorBmp);
    c.drawBitmap(bmp, 0, 0, p);
    return colorBmp;
  }
示例#5
0
文件: GameView.java 项目: ayin/hdos
 protected void onDraw(Canvas canvas) {
   canvas.drawColor(0xff333333);
   for (byte i = 0; i < 7; i++)
     for (byte j = 0; j < 6; j++)
       if (curMap[i][j] != -1)
         canvas.drawBitmap(
             brickBmp,
             new Rect(
                 (int) (curMap[i][j] * temp), 0, (int) (curMap[i][j] * temp + temp), (int) temp),
             new Rect(XOff + j * Size, i * Size, XOff + j * Size + Size, i * Size + Size),
             null);
   // canvas.drawBitmap(scaleBmp[(int)curFrame],dx, dy, null);
   canvas.drawBitmap(
       scaleBmp[(int) curFrame],
       new Rect(0, 0, 116, 63),
       new RectF(dx, dy, dx + Size * 2 + scaleXOff * 2, dy + Size + scaleYOff * 2),
       null);
   Paint p = new Paint();
   p.setColor(0xffffffff);
   p.setTextSize(textSize); // pixel
   canvas.drawText(
       "第  " + (index + 1) + " 关        " + "剩余 " + moveLeft + " 步",
       textOff,
       Size * 7 + textSize,
       p);
   if (state == 1) {
     for (byte i = 0; i < 30; i++) {
       if (explosionIndex[i] != 9) {
         Paint mPaint = new Paint();
         ColorMatrix cm = new ColorMatrix();
         cm.set(colorM[cBMP[i]]);
         mPaint.setColorFilter(new ColorMatrixColorFilter(cm));
         canvas.drawBitmap(
             explosionBmp[explosionIndex[i]],
             new Rect(0, 0, 49, 48),
             new RectF(XY[i][0], XY[i][1], XY[i][0] + Size, XY[i][1] + Size),
             mPaint);
       }
     }
   } else if (state == 3) {
     data.mainActivity.saveRecord(data.mainActivity.curLevel);
     ((HDOSActivity) cont).showDialog(0);
     state = 0;
   } else if (state == 4) {
     state = 0;
     ((HDOSActivity) cont).showDialog(1);
   }
 }
示例#6
0
  public static Bitmap blackWhiteBmp(Bitmap bmp) {
    // black and white

    int width = bmp.getWidth();
    int height = bmp.getHeight();

    ColorMatrix matrix = new ColorMatrix();
    float[] src = {
      0.308F, 0.609F, 0.082F, 0, 0, 0.308F, 0.609F, 0.082F, 0, 0, 0.308F, 0.609F, 0.082F, 0, 0, 0,
      0, 0, 1, 0
    };
    matrix.set(src);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
    Paint p = new Paint();
    p.setColorFilter(filter);
    Bitmap colorBmp = Bitmap.createBitmap(width, height, bmp.getConfig());
    Canvas c = new Canvas(colorBmp);
    c.drawBitmap(bmp, 0, 0, p);
    return colorBmp;
  }
示例#7
0
    public ComponentPeerView(Context context, boolean opaque_, long host) {
      super(context);
      this.host = host;
      setWillNotDraw(false);
      opaque = opaque_;

      setFocusable(true);
      setFocusableInTouchMode(true);
      setOnFocusChangeListener(this);
      requestFocus();

      // swap red and blue colours to match internal opengl texture format
      ColorMatrix colorMatrix = new ColorMatrix();

      float[] colorTransform = {
        0, 0, 1.0f, 0, 0, 0, 1.0f, 0, 0, 0, 1.0f, 0, 0, 0, 0, 0, 0, 0, 1.0f, 0
      };

      colorMatrix.set(colorTransform);
      paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    }