Ejemplo n.º 1
0
  public static Bitmap rotateBmp(Bitmap bmp, int angle) {

    int width = bmp.getWidth();
    int height = bmp.getHeight();
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
  }
Ejemplo n.º 2
0
  public static Bitmap roundedCornerBitmap(Bitmap bitmap, float radis) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = radis;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.WHITE);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
  }
Ejemplo n.º 3
0
 public static Bitmap zoomImage(Bitmap bmp, double newWidth, double newHeight) {
   float width = bmp.getWidth();
   float height = bmp.getHeight();
   Matrix matrix = new Matrix();
   float scaleWidth = ((float) newWidth) / width;
   float scaleHeight = ((float) newHeight) / height;
   matrix.postScale(scaleWidth, scaleHeight);
   Bitmap bitmap = Bitmap.createBitmap(bmp, 0, 0, (int) width, (int) height, matrix, true);
   return bitmap;
 }
Ejemplo n.º 4
0
  public static Bitmap matrixBmp(Bitmap bmp, int margin) {

    int width = bmp.getWidth();
    int height = bmp.getHeight();
    int px = UIUtils.dipToPx(margin);
    Matrix matrix = new Matrix();
    if (width > UIUtils.getWidth() - px) {
      float scale = ((float) (UIUtils.getWidth() - px) / width);
      matrix.postScale(scale, scale);
    } else {
      matrix.postScale(1, 1);
    }
    return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
  }
Ejemplo n.º 5
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;
  }
Ejemplo n.º 6
0
  public static Bitmap flipBmp(Bitmap bmp, int mode) {
    // mode 1: h, 2:v

    int width = bmp.getWidth();
    int height = bmp.getHeight();
    Matrix matrix = new Matrix();
    Matrix temp = new Matrix();
    float[] mirrorY = {-1, 0, 0, 0, 1, 0, 0, 0, 1};
    temp.setValues(mirrorY);
    matrix.postConcat(temp);
    if (mode == 2) {
      matrix.setRotate(180, width / 2, height / 2);
    }
    return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
  public static Bitmap blurBmp(Bitmap bmp, int Blur) {

    int pixels[] = new int[bmp.getWidth() * bmp.getHeight()];
    int pixelsRawSource[] = new int[bmp.getWidth() * bmp.getHeight() * 3];
    int pixelsRawNew[] = new int[bmp.getWidth() * bmp.getHeight() * 3];
    bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());

    for (int k = 1; k <= Blur; k++) {

      for (int i = 0; i < pixels.length; i++) {
        pixelsRawSource[i * 3 + 0] = Color.red(pixels[i]);
        pixelsRawSource[i * 3 + 1] = Color.green(pixels[i]);
        pixelsRawSource[i * 3 + 2] = Color.blue(pixels[i]);
      }

      int CurrentPixel = bmp.getWidth() * 3 + 3;
      for (int i = 0; i < bmp.getHeight() - 3; i++) {
        for (int j = 0; j < bmp.getWidth() * 3; j++) {
          CurrentPixel += 1;

          int sumColor = 0;
          sumColor = pixelsRawSource[CurrentPixel - bmp.getWidth() * 3];
          sumColor = sumColor + pixelsRawSource[CurrentPixel - 3];
          sumColor = sumColor + pixelsRawSource[CurrentPixel + 3];
          sumColor = sumColor + pixelsRawSource[CurrentPixel + bmp.getWidth() * 3];
          pixelsRawNew[CurrentPixel] = Math.round(sumColor / 4);
        }
      }

      for (int i = 0; i < pixels.length; i++) {
        pixels[i] =
            Color.rgb(pixelsRawNew[i * 3 + 0], pixelsRawNew[i * 3 + 1], pixelsRawNew[i * 3 + 2]);
      }
    }

    Bitmap bmpReturn = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888);
    bmpReturn.setPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());

    return bmpReturn;
  }