コード例 #1
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(primaryColor);
    //        List<Integer> list = new ArrayList<>();
    //        list.
    //        int count = (used+unused)/used;
    //        int[] colors = new int[]{primaryColor,};
    //        Shader mShader = new SweepGradient(0f,0f,getWidth(),getHeight(),new
    // int[]{Color.BLUE,Color.CYAN},null,Shader.TileMode.MIRROR);
    //        paint.setShader(mShader);
    float left = (float) ((used * 1.0 / (used + unused)) * getWidth());
    //        float right = (float) ((unused * 1.0 / (used + unused)) * getWidth());

    // canvas.drawRect(0f, 0f,getWidth(), getHeight(), paint);
    // canvas.drawRect(0f, 0f, left, getHeight(), paint);

    paint.setShadowLayer(8f, 0f, 4f, Color.BLACK);
    canvas.drawRoundRect(new RectF(0f, 0f, left, getHeight()), 3f, 3f, paint);
    paint.setAlpha(130);

    canvas.drawRoundRect(new RectF(0f, 0f, getWidth(), getHeight()), 3f, 3f, paint);
  }
コード例 #2
0
  @Override
  public Bitmap transform(final Bitmap source) {
    final Paint shadowPaint = new Paint();
    shadowPaint.setAntiAlias(true);
    shadowPaint.setShadowLayer(margin / 2, radius / 2, radius / 2, 0x30000000);

    Bitmap output =
        Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    canvas.drawRoundRect(
        new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin),
        radius,
        radius,
        shadowPaint);

    final Paint picPaint = new Paint();
    picPaint.setAntiAlias(true);
    picPaint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    canvas.drawRoundRect(
        new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin),
        radius,
        radius,
        picPaint);

    if (source != output) {
      source.recycle();
    }

    return output;
  }
コード例 #3
0
  @Override
  public void draw(Canvas canvas) {
    if (mRebuildShader) {
      mBitmapShader = new BitmapShader(mBitmap, mTileModeX, mTileModeY);
      if (mTileModeX == Shader.TileMode.CLAMP && mTileModeY == Shader.TileMode.CLAMP) {
        mBitmapShader.setLocalMatrix(mShaderMatrix);
      }
      mBitmapPaint.setShader(mBitmapShader);
      mRebuildShader = false;
    }

    if (mOval) {
      if (mBorderWidth > 0) {
        canvas.drawOval(mDrawableRect, mBitmapPaint);
        canvas.drawOval(mBorderRect, mBorderPaint);
      } else {
        canvas.drawOval(mDrawableRect, mBitmapPaint);
      }
    } else {
      if (mBorderWidth > 0) {
        canvas.drawRoundRect(
            mDrawableRect, Math.max(mCornerRadius, 0), Math.max(mCornerRadius, 0), mBitmapPaint);
        canvas.drawRoundRect(mBorderRect, mCornerRadius, mCornerRadius, mBorderPaint);
      } else {
        canvas.drawRoundRect(mDrawableRect, mCornerRadius, mCornerRadius, mBitmapPaint);
      }
    }
  }
コード例 #4
0
ファイル: Utils.java プロジェクト: dragonvirgo/shimatest2
 public static void drawTag(
     Canvas canvas,
     String text,
     float x,
     float y,
     Paint textPaint,
     Paint tagPaint,
     Paint shadowPaint) {
   final float MARGIN = 5f;
   final float SHADOW = 2f;
   FontMetrics fm = textPaint.getFontMetrics();
   float textWidth = textPaint.measureText(text); // 文字列の幅を取得
   float textX = x - textWidth / 2f; // 文字列の幅からX座標を計算
   float textY = y - (fm.ascent + fm.descent) / 2f; // 文字列の高さからY座標を計算
   // タグの影の矩形を計算
   float left = textX - MARGIN + SHADOW;
   float right = textX + MARGIN + SHADOW + textWidth;
   float top = textY - MARGIN + SHADOW + fm.ascent;
   float bottom = textY + MARGIN + SHADOW + fm.descent;
   RectF rect = new RectF(left, top, right, bottom);
   canvas.drawRoundRect(rect, MARGIN, MARGIN, shadowPaint); // タグの影を描画
   rect = translate(-SHADOW, -SHADOW, rect); // タグの影の部分をスライドする
   canvas.drawRoundRect(rect, MARGIN, MARGIN, tagPaint); // タグの描画
   canvas.drawText(text, textX, textY, textPaint); // 文字列の描画
 }
コード例 #5
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // calculate the left and right values
    float right = this.getWidth() - this.getPaddingRight();
    float left = right - this.getWidth() + this.getPaddingLeft();
    float height = this.getHeight() - this.getPaddingTop() - this.getPaddingBottom();
    float radius = height / 2; // 圓半徑

    oval.set(left, 0, right, height);
    if (this.isChecked()) {
      paint.setColor(Color.parseColor("#4B96C2"));
      // paint.setColor(Color.parseColor("#5a7fc0"));
      canvas.drawRoundRect(oval, radius, radius, paint);
      paint.setColor(Color.WHITE);
      canvas.drawCircle(right - radius, radius, radius - SWITCH_BOUND, paint);
    } else {
      paint.setColor(Color.GRAY);
      canvas.drawRoundRect(oval, radius, radius, paint);
      paint.setColor(Color.WHITE);
      canvas.drawCircle(left + radius, radius, radius - SWITCH_BOUND, paint);
    }

    canvas.save();
  }
コード例 #6
0
  @Override
  protected void drawCallout(Canvas canvas, NMapView mapView, boolean shadow, long when) {

    adjustTextBounds(mapView);

    stepAnimations(canvas, mapView, when);

    // Draw inner info window
    canvas.drawRoundRect(mTempRectF, CALLOUT_ROUND_RADIUS_X, CALLOUT_ROUND_RADIUS_Y, mInnerPaint);

    // Draw border for info window
    canvas.drawRoundRect(mTempRectF, CALLOUT_ROUND_RADIUS_X, CALLOUT_ROUND_RADIUS_Y, mBorderPaint);

    // Draw bottom tag
    if (CALLOUT_TAG_WIDTH > 0 && CALLOUT_TAG_HEIGHT > 0) {
      float x = mTempRectF.centerX();
      float y = mTempRectF.bottom;

      Path path = mPath;
      path.reset();

      path.moveTo(x - CALLOUT_TAG_WIDTH, y);
      path.lineTo(x, y + CALLOUT_TAG_HEIGHT);
      path.lineTo(x + CALLOUT_TAG_WIDTH, y);
      path.close();

      canvas.drawPath(path, mInnerPaint);
      canvas.drawPath(path, mBorderPaint);
    }

    //  Draw title
    canvas.drawText(mOverlayItem.getTitle(), mOffsetX, mOffsetY, mTextPaint);
  }
コード例 #7
0
ファイル: TagView.java プロジェクト: 601367322/banyou
  @Override
  protected void onDraw(Canvas canvas) {
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(mBackgroundColor);
    canvas.drawRoundRect(mRectF, mBorderRadius, mBorderRadius, mPaint);

    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(mBorderWidth);
    mPaint.setColor(mBorderColor);
    canvas.drawRoundRect(mRectF, mBorderRadius, mBorderRadius, mPaint);

    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(mTextColor);

    if (mTextDirection == View.TEXT_DIRECTION_RTL) {
      float tmpX = getWidth() / 2 + fontW / 2;
      for (char c : mAbstractText.toCharArray()) {
        String sc = String.valueOf(c);
        tmpX -= mPaint.measureText(sc);

        Paint.FontMetricsInt fontMetrics = mPaint.getFontMetricsInt();
        int baseline =
            ((int) getHeight() - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
        canvas.drawText(sc, tmpX, baseline, mPaint);
      }
    } else {

      Paint.FontMetricsInt fontMetrics = mPaint.getFontMetricsInt();
      int baseline =
          ((int) getHeight() - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;

      canvas.drawText(mAbstractText, getWidth() / 2 - fontW / 2, baseline, mPaint);
    }
  }
コード例 #8
0
  @Override
  public void draw(Canvas canvas) {
    super.draw(canvas);
    int totalW = getWidth();
    int totalH = getHeight();
    // rotate canvas first
    canvas.rotate(45, totalW / 2, totalH / 2);

    totalW /= 1.2;
    totalH /= 1.4;
    mMaxLeftRectWidth = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;

    RectF leftRect = new RectF();
    if (mLeftRectGrowMode) {
      leftRect.left = 0;
      leftRect.right = leftRect.left + mLeftRectWidth;
      leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
      leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
    } else {
      leftRect.right = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
      leftRect.left = leftRect.right - mLeftRectWidth;
      leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
      leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
    }

    canvas.drawRoundRect(leftRect, CONST_RADIUS, CONST_RADIUS, mPaint);

    RectF rightRect = new RectF();
    rightRect.bottom = (totalH + CONST_RIGHT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
    rightRect.left = (totalW + CONST_LEFT_RECT_W) / 2;
    rightRect.right = rightRect.left + CONST_RECT_WEIGHT;
    rightRect.top = rightRect.bottom - mRightRectWidth;
    canvas.drawRoundRect(rightRect, CONST_RADIUS, CONST_RADIUS, mPaint);
  }
コード例 #9
0
 protected void onDraw(Canvas paramCanvas) {
   // today round
   if (mIsToday) {
     Paint painta = new Paint();
     painta.setStyle(Paint.Style.STROKE);
     painta.setColor(Color.BLACK);
     painta.setAntiAlias(true);
     Rect rect = paramCanvas.getClipBounds();
     RectF rt = new RectF(rect);
     rt.inset(getMeasuredWidth() / 12, getMeasuredHeight() / 12);
     paramCanvas.drawRoundRect(rt, getMeasuredWidth() / 5, getMeasuredHeight() / 5, painta);
     Paint paintb = new Paint();
     paintb.setColor(Color.GRAY);
     paintb.setAntiAlias(true);
     paintb.setAlpha(50);
     paramCanvas.drawRoundRect(rt, getMeasuredWidth() / 6, getMeasuredWidth() / 6, paintb);
   }
   // solar text
   Paint paint1 = new Paint();
   paint1.setAntiAlias(true);
   paint1.setFakeBoldText(true);
   paint1.setTextSize(getMeasuredWidth() / 2);
   if (mDay.mIsWeekEnd) {
     paint1.setColor(ECalendarActivity.mHolidayColor);
   } else {
     paint1.setColor(Color.BLACK);
   }
   Rect text = new Rect();
   paint1.getTextBounds(mDay.mSolarDay, 0, mDay.mSolarDay.length(), text);
   int w = getMeasuredWidth();
   int w1 = text.width();
   float fw = (w - w1) / 2;
   float fh = getMeasuredHeight() / 2 + 1;
   paramCanvas.drawText(mDay.mSolarDay, fw, fh, paint1);
   // lunar text
   Paint paint2 = new Paint();
   paint2.setAntiAlias(true);
   paint2.setTextSize(getMeasuredWidth() / 4);
   if (mDay.mIsFestival) {
     paint2.setColor(ECalendarActivity.mHolidayColor);
   } else {
     paint2.setColor(Color.BLACK);
   }
   paint2.getTextBounds(mDay.mLunarDay, 0, mDay.mLunarDay.length(), text);
   w1 = text.width();
   fw = (w - w1) / 2;
   fh = getMeasuredHeight() / 2 + 2 + text.height();
   paramCanvas.drawText(mDay.mLunarDay, fw, fh, paint2);
   if (mDay.mHasDiary) {
     Paint pd = new Paint();
     pd.setStyle(Paint.Style.STROKE);
     pd.setColor(ECalendarActivity.mHolidayColor);
     pd.setStrokeWidth(2);
     Rect rect = paramCanvas.getClipBounds();
     RectF rt = new RectF(rect);
     rt.inset(getMeasuredWidth() / 12, getMeasuredHeight() / 12);
     paramCanvas.drawLine(rt.left + rt.width() / 4, rt.top, rt.right - rt.width() / 4, rt.top, pd);
   }
 }
コード例 #10
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(0);
    paint.setTextSize(25);
    Rect bounds = new Rect();
    float bottom = 0;
    paint.setARGB(255, 255, 255, 255);
    if (searched == null) return;
    for (Match m : searched) {
      float start = bottom;
      String s = "Match 216498464";
      canvas.drawLine(5, bottom, getWidth() - 5, bottom, paint);
      paint.getTextBounds(s.toUpperCase(), 0, s.length(), bounds);
      paint.setARGB(255, 255, 255, 255);
      s = "Match " + m.getMatchNum();
      canvas.drawText(s, 10, bottom + bounds.height() + 5, paint);
      bottom = bottom + bounds.height() + 10;

      s = "123654987";
      paint.getTextBounds(s.toUpperCase(), 0, s.length(), bounds);
      paint.setARGB(255, 255, 0, 0);
      canvas.drawRoundRect(
          new RectF(getWidth() / 4 - 5, bottom, getWidth(), bottom + bounds.height() + 10),
          6,
          6,
          paint);
      paint.setARGB(255, 255, 255, 255);
      bottom = bottom + bounds.height() + 10;
      s = m.getRedTeam()[0].getNumber() + "";
      canvas.drawText(s, getWidth() / 4, bottom - 5, paint);
      s = m.getRedTeam()[1].getNumber() + "";
      canvas.drawText(s, getWidth() / 2, bottom - 5, paint);
      s = m.getRedTeam()[2].getNumber() + "";
      canvas.drawText(s, getWidth() / 4 * 3, bottom - 5, paint);

      paint.setARGB(255, 0, 0, 255);
      canvas.drawRoundRect(
          new RectF(getWidth() / 4 - 5, bottom, getWidth(), bottom + bounds.height() + 10),
          6,
          6,
          paint);
      paint.setARGB(255, 255, 255, 255);
      bottom = bottom + bounds.height() + 10;
      canvas.drawText(s, getWidth() / 4, bottom - 5, paint);
      s = m.getBlueTeam()[0].getNumber() + "";
      canvas.drawText(s, getWidth() / 2, bottom - 5, paint);
      s = m.getBlueTeam()[1].getNumber() + "";
      canvas.drawText(s, getWidth() / 4 * 3, bottom - 5, paint);
      s = m.getBlueTeam()[2].getNumber() + "";
      bottom += 5;
    }
    height = Math.round(bottom + 1);
  }
コード例 #11
0
  @Override
  protected void dispatchDraw(Canvas canvas) {

    RectF drawRect = new RectF();
    drawRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());

    canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
    canvas.drawRoundRect(drawRect, 5, 5, borderPaint);

    super.dispatchDraw(canvas);
  }
コード例 #12
0
  private void drawChecked(Canvas canvas) {
    float size = mBoxSize - mStrokeSize * 2;
    float x = mBoxRect.left + mStrokeSize;
    float y = mBoxRect.top + mStrokeSize;

    if (isRunning()) {
      if (mAnimProgress < FILL_TIME) {
        float progress = mAnimProgress / FILL_TIME;
        float fillWidth = (mBoxSize - mStrokeSize) / 2f * progress;
        float padding = mStrokeSize / 2f + fillWidth / 2f - 0.5f;

        mPaint.setColor(ColorUtil.getMiddleColor(mPrevColor, mCurColor, progress));
        mPaint.setStrokeWidth(fillWidth);
        mPaint.setStyle(Paint.Style.STROKE);
        canvas.drawRect(
            mBoxRect.left + padding,
            mBoxRect.top + padding,
            mBoxRect.right - padding,
            mBoxRect.bottom - padding,
            mPaint);

        mPaint.setStrokeWidth(mStrokeSize);
        canvas.drawRoundRect(mBoxRect, mCornerRadius, mCornerRadius, mPaint);
      } else {
        float progress = (mAnimProgress - FILL_TIME) / (1f - FILL_TIME);

        mPaint.setColor(mCurColor);
        mPaint.setStrokeWidth(mStrokeSize);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawRoundRect(mBoxRect, mCornerRadius, mCornerRadius, mPaint);

        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.MITER);
        mPaint.setStrokeCap(Paint.Cap.BUTT);
        mPaint.setColor(mTickColor);

        canvas.drawPath(getTickPath(mTickPath, x, y, size, progress, true), mPaint);
      }
    } else {
      mPaint.setColor(mCurColor);
      mPaint.setStrokeWidth(mStrokeSize);
      mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
      canvas.drawRoundRect(mBoxRect, mCornerRadius, mCornerRadius, mPaint);

      mPaint.setStyle(Paint.Style.STROKE);
      mPaint.setStrokeJoin(Paint.Join.MITER);
      mPaint.setStrokeCap(Paint.Cap.BUTT);
      mPaint.setColor(mTickColor);

      canvas.drawPath(getTickPath(mTickPath, x, y, size, 1f, true), mPaint);
    }
  }
コード例 #13
0
 @Override
 public void draw(Canvas canvas) {
   //		Log.w(TAG, "Draw: " + mScaleType.toString());
   if (mBorderWidth > 0) {
     canvas.drawRoundRect(mBorderRect, mCornerRadius, mCornerRadius, mBorderPaint);
     canvas.drawRoundRect(
         mDrawableRect,
         Math.max(mCornerRadius - mBorderWidth, 0),
         Math.max(mCornerRadius - mBorderWidth, 0),
         mBitmapPaint);
   } else {
     canvas.drawRoundRect(mDrawableRect, mCornerRadius, mCornerRadius, mBitmapPaint);
   }
 }
コード例 #14
0
  @Override
  public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();

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

    Bitmap.Config config =
        source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
    Bitmap bitmap = mBitmapPool.get(width, height, config);
    if (bitmap == null) {
      bitmap = Bitmap.createBitmap(width, height, config);
    }

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    canvas.drawRoundRect(
        new RectF(margin, margin, width - margin, height - margin), radius, radius, paint);

    source.recycle();

    return BitmapResource.obtain(bitmap, mBitmapPool);
  }
コード例 #15
0
  @Override
  public Bitmap transform(final Bitmap source) {
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));

    Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    canvas.drawRoundRect(
        new RectF(0, 0, source.getWidth(), source.getHeight()), radius, radius, paint);

    if (source != output) {
      source.recycle();
    }

    //        Paint paint1 = new Paint();
    //        paint1.setColor(Color.RED);
    //        paint1.setStyle(Style.STROKE);
    //        paint1.setAntiAlias(true);
    //        paint1.setStrokeWidth(2);
    //        canvas.drawCircle((source.getWidth() - margin)/2, (source.getHeight() - margin)/2,
    // radius-2, paint1);

    return output;
  }
コード例 #16
0
ファイル: DragableSpace.java プロジェクト: pellucide/BigPage
  public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // We have to make sure our rounded corners have an alpha channel in most cases
    // color is arbitrary. This could be any color that was fully opaque (alpha = 255)
    final int color = 0xff222222;

    // We're just reusing xferPaint to paint a normal looking rounded box,
    // the roundPx is the amount we're rounding by.
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, w, h);
    final RectF rectF = new RectF(rect);

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

    // We're going to apply this paint using a porter-duff xfer mode.
    // This will allow us to only overwrite certain pixels.
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
  }
コード例 #17
0
ファイル: BitmpUtils.java プロジェクト: MelonRice/SmartNurse
  /**
   * @param x 图像的宽度
   * @param y 图像的高度
   * @param image 源图片
   * @param outerRadiusRat 圆角的大小
   * @return 圆角图片
   */
  public static Bitmap createFramedPhoto(int x, int y, Bitmap image, float outerRadiusRat) {
    // 根据源文件新建一个darwable对象
    Drawable imageDrawable = new BitmapDrawable(image);

    // 新建一个新的输出图片
    Bitmap output = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // 新建一个矩形
    RectF outerRect = new RectF(0, 0, x, y);

    // 产生一个红色的圆角矩形
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    canvas.drawRoundRect(outerRect, outerRadiusRat, outerRadiusRat, paint);

    // 将源图片绘制到这个圆角矩形上
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    imageDrawable.setBounds(0, 0, x, y);
    canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG);
    imageDrawable.draw(canvas);
    canvas.restore();

    return output;
  }
コード例 #18
0
  /**
   * 将图片转化为圆形头像 @Title: toRoundBitmap
   *
   * @throws
   */
  public static Bitmap toRoundBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float roundPx;
    float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
    if (width <= height) {
      roundPx = width / 2;

      left = 0;
      top = 0;
      right = width;
      bottom = width;

      height = width;

      dst_left = 0;
      dst_top = 0;
      dst_right = width;
      dst_bottom = width;
    } else {
      roundPx = height / 2;

      float clip = (width - height) / 2;

      left = clip;
      right = width - clip;
      top = 0;
      bottom = height;
      width = height;

      dst_left = 0;
      dst_top = 0;
      dst_right = height;
      dst_bottom = height;
    }

    Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom);
    final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
    final RectF rectF = new RectF(dst);

    paint.setAntiAlias(true); // 设置画笔无锯齿

    canvas.drawARGB(0, 0, 0, 0); // 填充整个Canvas

    // 以下有两种方法画圆,drawRounRect和drawCircle
    canvas.drawRoundRect(
        rectF, roundPx, roundPx, paint); // 画圆角矩形,第一个参数为图形显示区域,第二个参数和第三个参数分别是水平圆角半径和垂直圆角半径。
    // canvas.drawCircle(roundPx, roundPx, roundPx, paint);

    paint.setXfermode(
        new PorterDuffXfermode(
            Mode.SRC_IN)); // 设置两张图片相交时的模式,参考http://trylovecatch.iteye.com/blog/1189452
    canvas.drawBitmap(bitmap, src, dst, paint); // 以Mode.SRC_IN模式合并bitmap和已经draw了的Circle

    return output;
  }
コード例 #19
0
 public Bitmap createCodeBitmap() {
   Bitmap mBitmap = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight, Config.ARGB_8888);
   Canvas mCanvas = new Canvas(mBitmap);
   Paint mPaint = new Paint();
   RectF rect = new RectF();
   rect.left = 0;
   rect.right = mBitmapWidth;
   rect.top = mBitmapHeight;
   rect.bottom = 0;
   mCanvas.drawRoundRect(rect, 10, 10, mPaint);
   mRandomCode = CreateCodeSting(); // 获得随机的验证码字符串.
   mCanvas.drawColor(Color.GRAY);
   mPaint.setTextSize(mFontSize);
   for (int i = 0; i < mRandomCode.length(); i++) {
     randomCodeTextStyle(mPaint);
     randomPadding();
     mCanvas.drawText(mRandomCode.charAt(i) + "", mPaddingLeft, mPaddingTop, mPaint);
   }
   for (int j = 0; j < mLineNumber; j++) {
     drawRandomLine(mCanvas, mPaint);
   }
   mCanvas.save(Canvas.ALL_SAVE_FLAG);
   mCanvas.restore();
   return mBitmap;
 }
コード例 #20
0
  /**
   * Drawing src bitmap to dest bitmap with rounded corners
   *
   * @param src source bitmap
   * @param dest destination bitmap
   * @param radius radius in destination bitmap scale
   * @param clearColor clear color
   */
  public static void drawRoundedCorners(Bitmap src, Bitmap dest, int radius, int clearColor) {
    clearBitmap(dest, clearColor);
    Canvas canvas = new Canvas(dest);

    Rect sourceRect = WorkCache.RECT1.get();
    Rect destRect = WorkCache.RECT2.get();
    sourceRect.set(0, 0, src.getWidth(), src.getHeight());
    destRect.set(0, 0, dest.getWidth(), dest.getHeight());

    RectF roundRect = WorkCache.RECTF1.get();
    roundRect.set(0, 0, dest.getWidth(), dest.getHeight());

    Paint paint = WorkCache.PAINT.get();
    paint.reset();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.RED);
    paint.setAntiAlias(true);
    canvas.drawRoundRect(roundRect, radius, radius, paint);

    paint.reset();
    paint.setFilterBitmap(true);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, sourceRect, destRect, paint);

    canvas.setBitmap(null);
  }
コード例 #21
0
ファイル: CellEnum.java プロジェクト: danieltf/buscaminas
 public void paintBitmap(Context context, Canvas c, Rect dest) {
   int color0 = Color.argb(0xFF, 196, 181, 51);
   int color1 = Color.argb(0xFF, 251, 219, 39);
   int color2 = Color.argb(0xFF, 255, 239, 151);
   int border = Color.argb(0xFF, 220, 200, 80);
   Paint p = new Paint();
   p.setAntiAlias(true);
   float width = dest.width() / 20.0f;
   float insideSize = dest.width() - 2 * width;
   RectF inside1 =
       new RectF(
           dest.left + width - 1,
           dest.top + width - 1,
           dest.right - width + 1,
           dest.bottom - width + 1);
   RectF inside =
       new RectF(dest.left + width, dest.top + width, dest.right - width, dest.bottom - width);
   LinearGradient linear =
       new LinearGradient(
           inside1.left,
           inside1.top + insideSize / 3,
           inside1.right,
           inside1.top + 2 * insideSize / 3,
           new int[] {color0, color1, color2},
           null,
           Shader.TileMode.CLAMP);
   p.setShader(linear);
   c.drawRoundRect(inside1, width, width, p);
   p.setShader(null);
   p.setColor(border);
   Path path = new Path();
   path.addRoundRect(inside, width, width, Path.Direction.CCW);
   path.addRect(new RectF(dest), Path.Direction.CW);
   c.drawPath(path, p);
 }
コード例 #22
0
  public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, boolean square) {
    int width = 0;
    int height = 0;
    if (square) {
      if (bitmap.getWidth() < bitmap.getHeight()) {
        width = bitmap.getWidth();
        height = bitmap.getWidth();
      } else {
        width = bitmap.getHeight();
        height = bitmap.getHeight();
      }
    } else {
      height = bitmap.getHeight();
      width = bitmap.getWidth();
    }

    Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, width, height);
    final RectF rectF = new RectF(rect);
    final float roundPx = 90;

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

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
  }
コード例 #23
0
ファイル: MyEditText.java プロジェクト: sserhr/ReNewer
  @Override
  protected void onDraw(Canvas canvas) {
    Log.d("hr123", "MyEditOnDraw");
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(2);
    if (this.isFocused() == true) {
      Log.d("hr123", "MyEditOnDrawFocus");
      paint.setColor(Color.parseColor("#F0F0F0"));
    } else {
      Log.d("hr123", "MyEditOnDrawUnFocus");
      paint.setColor(Color.parseColor("#11cd6e"));
    }

    canvas.drawRoundRect(
        new RectF(
            2 + this.getScrollX(),
            2 + this.getScrollY(),
            this.getWidth() - 3 + this.getScrollX(),
            this.getHeight() + this.getScrollY() - 1),
        3,
        3,
        paint);
    super.onDraw(canvas);
  }
コード例 #24
0
ファイル: Frame.java プロジェクト: TexnologiaLog/Testing
  private Bitmap FrameProcessingBitmap() {
    Bitmap bm1 = null;
    Bitmap newBitmap = null;

    try {
      bm1 = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(path));

      int w = bm1.getWidth();
      int h = bm1.getHeight();

      Bitmap.Config config = bm1.getConfig();
      if (config == null) {
        config = Bitmap.Config.ARGB_8888;
      }

      newBitmap = Bitmap.createBitmap(w, h, config);
      Canvas newCanvas = new Canvas(newBitmap);
      newCanvas.drawColor(Color.WHITE);

      Paint paint = new Paint();
      paint.setColor(Color.BLACK);
      Rect frame = new Rect((int) (w * 0.05), (int) (w * 0.05), (int) (w * 0.95), (int) (h * 0.95));
      RectF frameF = new RectF(frame);
      newCanvas.drawRoundRect(frameF, (float) (w * 0.05), (float) (h * 0.05), paint);

      paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
      newCanvas.drawBitmap(bm1, 0, 0, paint);

    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return newBitmap;
  }
コード例 #25
0
ファイル: ShadowGenerator.java プロジェクト: Sai-Teja/Carbon
  public static Shadow generateShadow(View view, float elevation) {
    if (!software && renderScript == null) {
      try {
        renderScript = RenderScript.create(view.getContext());
        blurShader = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
      } catch (RSRuntimeException ignore) {
        software = true;
      }
    }

    CornerView cornerView = (CornerView) view;

    int e = (int) Math.ceil(elevation);
    int c = Math.max(e, cornerView.getCornerRadius());

    Bitmap bitmap;
    bitmap = Bitmap.createBitmap(e * 2 + 2 * c + 1, e * 2 + 2 * c + 1, Bitmap.Config.ARGB_8888);

    Canvas shadowCanvas = new Canvas(bitmap);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(0xff000000);

    roundRect.set(e, e, bitmap.getWidth() - e, bitmap.getHeight() - e);
    shadowCanvas.drawRoundRect(roundRect, c, c, paint);

    blur(bitmap, elevation / 2);

    return new NinePatchShadow(bitmap, elevation, c);
  }
コード例 #26
0
  @Override
  protected Bitmap transform(BitmapPool pool, Bitmap source, int outWidth, int outHeight) {
    int sourceWidth = source.getWidth();
    int sourceHeight = source.getHeight();
    double outRatio = (double) outWidth / (double) outHeight;
    int x = 0;
    int width = sourceWidth;
    int height = (int) (width / outRatio);
    int y = (sourceHeight - height) / 2;
    if (height >= sourceHeight) {
      height = sourceHeight;
      width = (int) (outRatio * height);
      y = 0;
      x = (sourceWidth - width) / 2;
    }
    Bitmap bitmap = Bitmap.createBitmap(source, x, y, width, height);

    // 圆角
    Bitmap output = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF dst = new RectF(0, 0, outWidth, outHeight);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(dst, mRadius, mRadius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, src, dst, paint);

    return output;
  }
コード例 #27
0
ファイル: PenCreatorView.java プロジェクト: kaffeel/Freehand
    @Override
    public void onDraw(final Canvas c) {
      // Draw the alpha pattern
      mAlphaPattern.draw(c);

      // Draw the shader that shows how transparent a colors looks at a given alpha on top of the
      // alpha pattern
      shaderPaint.setShader(
          new LinearGradient(
              borderSize, 0, this.getWidth() - borderSize, 0, 0, color, TileMode.CLAMP));
      c.drawRect(
          borderSize,
          borderSize,
          this.getWidth() - borderSize,
          this.getHeight() - borderSize,
          shaderPaint);

      // Draw the transparency label on top of that stuff
      c.drawText(
          "Transparency",
          this.getWidth() / 2,
          this.getHeight() / 2 + labelPaint.getTextSize() / 2.0f,
          labelPaint);

      // Draw the alpha tracker on top of everything else
      final float xPos = alphaToXPos(alpha);
      final float rectWidth = 2 * mDensity;
      final RectF r = new RectF();
      r.left = xPos - rectWidth;
      r.right = xPos + rectWidth;
      r.top = 0;
      r.bottom = this.getHeight();
      c.drawRoundRect(r, rectWidth, rectWidth, trackerPaint);
    }
コード例 #28
0
 private void drawOuterBorder(Canvas canvas) {
   Paint paint = theme.getOuterBorderPaint();
   float radius = theme.getOuterBorderRadius();
   float width = paint.getStrokeWidth() / 2;
   RectF rect = new RectF(width, width, getMeasuredWidth() - width, getMeasuredHeight() - width);
   canvas.drawRoundRect(rect, radius, radius, paint);
 }
コード例 #29
0
  @Override
  public void draw(Canvas canvas) {
    canvas.drawRoundRect(mRectF, mRadius, mRadius, mBorderPaint);

    Path path = new Path();
    path.moveTo(mRectF.right - 2 * mOffsetY - mOffsetX, mRectF.bottom);
    path.lineTo(mRectF.right - (2 * mOffsetY + mRadius) / 2 - mOffsetX, mRectF.bottom + mOffsetY);
    path.lineTo(mRectF.right - mRadius - mOffsetX, mRectF.bottom);

    float x = 0;
    float y = mRectF.centerY();

    String text = "One Piece";
    float[] characterWidths = new float[text.length()];
    int characterNum = mTextPaint.getTextWidths(text, characterWidths);

    float textWidth = 0f;
    for (int i = 0; i < characterNum; i++) {
      textWidth += characterWidths[i];
    }
    canvas.save();
    canvas.translate(mRectF.width() / 2 - textWidth / 2, 0);
    canvas.drawText("one piece", x, y, mTextPaint);

    canvas.restore();
    canvas.drawPath(path, mBorderPaint);
  }
コード例 #30
0
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    // Get the map projection to convert lat/long to screen coordinates
    Projection projection = mapView.getProjection();

    Point lPoint = new Point();
    projection.toPixels(locationPoint, lPoint);

    // Draw the overlay
    if (shadow == false) {
      if (friendLocations.size() > 0) {
        Iterator<String> e = friendLocations.keySet().iterator();
        do {
          // Get the name and location of each contact
          String name = e.next();
          Location location = friendLocations.get(name);

          // Convert the lat / long to a Geopoint
          Double latitude = location.getLatitude() * 1E6;
          Double longitude = location.getLongitude() * 1E6;
          GeoPoint geopoint = new GeoPoint(latitude.intValue(), longitude.intValue());

          // Ensure each contact is within 10km
          float dist = location.distanceTo(getLocation());
          if (dist < 10000) {
            Point point = new Point();
            projection.toPixels(geopoint, point);

            // Draw a line connecting the contact to your current location.
            canvas.drawLine(lPoint.x, lPoint.y, point.x, point.y, paint);

            // Draw a marker at the contact's location.
            RectF oval =
                new RectF(
                    point.x - markerRadius,
                    point.y - markerRadius,
                    point.x + markerRadius,
                    point.y + markerRadius);

            canvas.drawOval(oval, backPaint);
            oval.inset(2, 2);
            canvas.drawOval(oval, paint);

            // Draw the contact's name next to their position.
            float textWidth = paint.measureText(name);
            float textHeight = paint.getTextSize();
            RectF textRect =
                new RectF(
                    point.x + markerRadius,
                    point.y - textHeight,
                    point.x + markerRadius + 8 + textWidth,
                    point.y + 4);
            canvas.drawRoundRect(textRect, 3, 3, backPaint);
            canvas.drawText(name, point.x + markerRadius + 4, point.y, paint);
          }
        } while (e.hasNext());
      }
    }
    super.draw(canvas, mapView, shadow);
  }