Ejemplo n.º 1
0
  // ==============================================================================
  public final int[] renderGlyph(
      char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) {
    Path p = new Path();
    paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds(boundsF, true);
    matrix.mapRect(boundsF);

    boundsF.roundOut(bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = Math.max(1, bounds.height());

    Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(bm);
    matrix.postTranslate(-bounds.left, -bounds.top);
    c.setMatrix(matrix);
    c.drawPath(p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded];

    bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
  }
Ejemplo n.º 2
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;
  }