Example #1
0
 /**
  * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode.
  *
  * @param barcode A bitmap of the captured image.
  * @param scaleFactor amount by which thumbnail was scaled
  * @param rawResult The decoded results which contains the points to draw.
  */
 private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) {
   ResultPoint[] points = rawResult.getResultPoints();
   if (points != null && points.length > 0) {
     Canvas canvas = new Canvas(barcode);
     Paint paint = new Paint();
     paint.setColor(getResources().getColor(R.color.result_points));
     if (points.length == 2) {
       paint.setStrokeWidth(4.0f);
       drawLine(canvas, paint, points[0], points[1], scaleFactor);
     } else if (points.length == 4
         && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A
             || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
       // Hacky special case -- draw two lines, for the barcode and metadata
       drawLine(canvas, paint, points[0], points[1], scaleFactor);
       drawLine(canvas, paint, points[2], points[3], scaleFactor);
     } else {
       paint.setStrokeWidth(10.0f);
       for (ResultPoint point : points) {
         if (point != null) {
           canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint);
         }
       }
     }
   }
 }
Example #2
0
  public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;
    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
      finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    else finalBitmap = bitmap;
    Bitmap output =
        Bitmap.createBitmap(
            finalBitmap.getWidth(), finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(), finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(
        finalBitmap.getWidth() / 2 + 0.7f,
        finalBitmap.getHeight() / 2 + 0.7f,
        finalBitmap.getWidth() / 2 + 0.1f,
        paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
  }
  /**
   * 重叠合并两张图片,合并后的大小等同于作为底图的图片大小
   *
   * @param background:下层图,即底图
   * @param foreground:上层图,即前置图
   * @return 合并后的Bitmap
   */
  public static Bitmap toConformBitmap(Bitmap background, Bitmap foreground, Paint paint) {
    if (null == background) {
      return null;
    }

    int bgWidth = background.getWidth();
    int bgHeight = background.getHeight();
    // int fgWidth = foreground.getWidth();
    // int fgHeight = foreground.getHeight();
    // create the new blank bitmap 创建一个新的和SRC长度宽度一样的位图
    Bitmap newbmp = null;
    try {
      newbmp = Bitmap.createBitmap(bgWidth, bgHeight, Config.ARGB_8888);
    } catch (OutOfMemoryError e) {
      // OOM,return null
      return null;
    }
    Canvas cv = new Canvas(newbmp);
    // draw bg into
    cv.drawBitmap(background, 0, 0, paint); // 在 0,0坐标开始画入bg
    // draw fg into
    if (null != foreground) {
      cv.drawBitmap(foreground, 0, 0, paint); // 在 0,0坐标开始画入fg ,可以从任意位置画入
    }
    // save all clip
    cv.save(Canvas.ALL_SAVE_FLAG); // 保存
    // store
    cv.restore(); // 存储
    return newbmp;
  }
  private void generateBitmap(float fraction) {
    mBitmap = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(mBitmap);

    canvas.clipRect(0, (int) (64 * fraction), 64, 0);
    canvas.drawARGB(255, 255, 255, 255);
  }
  @Override
  protected void onDraw(Canvas canvas) {
    int i = 1;
    if (percentList != null && !percentList.isEmpty()) {
      for (Float f : percentList) {
        rect.set(
            BAR_SIDE_MARGIN * i + barWidth * (i - 1),
            topMargin,
            (BAR_SIDE_MARGIN + barWidth) * i,
            getHeight() - bottomTextHeight - TEXT_TOP_MARGIN);
        canvas.drawRect(rect, bgPaint);
        rect.set(
            BAR_SIDE_MARGIN * i + barWidth * (i - 1),
            topMargin + (int) ((getHeight() - topMargin) * percentList.get(i - 1)),
            (BAR_SIDE_MARGIN + barWidth) * i,
            getHeight() - bottomTextHeight - TEXT_TOP_MARGIN);
        canvas.drawRect(rect, fgPaint);
        i++;
      }
    }

    if (bottomTextList != null && !bottomTextList.isEmpty()) {
      i = 1;
      for (String s : bottomTextList) {
        canvas.drawText(
            s,
            BAR_SIDE_MARGIN * i + barWidth * (i - 1) + barWidth / 2,
            getHeight() - bottomTextDescent,
            textPaint);
        i++;
      }
    }
  }
Example #6
0
  private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
      return null;
    }

    if (drawable instanceof BitmapDrawable) {
      return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
      Bitmap bitmap;

      if (drawable instanceof ColorDrawable) {
        bitmap =
            Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
      } else {
        bitmap =
            Bitmap.createBitmap(
                drawable.getIntrinsicWidth() + 1, drawable.getIntrinsicHeight() + 1, BITMAP_CONFIG);
      }

      Canvas canvas = new Canvas(bitmap);
      drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
      drawable.draw(canvas);
      return bitmap;
    } catch (OutOfMemoryError e) {
      return null;
    }
  }
  @Override
  public void draw(Canvas canvas) {
    final float scale = mDisplayScale;
    boolean isRecycled = false;
    if (scale != 1f) {
      canvas.save();
      canvas.scale(scale, scale);

      try {
        super.draw(canvas);
      } catch (Exception ex) {
        isRecycled = true;
      }

      canvas.restore();
    } else {
      try {
        super.draw(canvas);
      } catch (Exception ex) {
        isRecycled = true;
      }
    }

    Check.d(!isRecycled, mTraceContent);
  }
Example #8
0
File: Unit.java Project: talah/BBTH
  public void drawHealthBar(Canvas canvas, boolean serverDraw) {
    if (isDead()) return;

    tempPaint.set(paint);
    paint.setStyle(Style.FILL);

    float radius = getRadius();
    float border = 1f;

    float left = getX() - radius;
    float top = (serverDraw) ? getY() + (radius * 2f) : getY() - (radius * 2f);
    float right = left + 2f * radius;
    float bottom = top + radius / 2f;

    paint.setColor(Color.WHITE);
    canvas.drawRect(left - border, top - border, right + border, bottom + border, paint);

    paint.setColor(Color.RED);
    canvas.drawRect(left, top, right, bottom, paint);

    paint.setColor(Color.GREEN);
    float greenStopX = MathUtils.scale(0f, getStartingHealth(), left, right, getHealth(), true);
    canvas.drawRect(left, top, greenStopX, bottom, paint);

    paint.set(tempPaint);
  }
Example #9
0
 @Override
 public void draw(Canvas canvas) {
   canvas.drawText(
       String.format("%.0f", value), centerX - correction, (centerY) + marginTop, digitPaint);
   canvas.drawText(
       units, centerX + textSize * 1.2f - correction, (centerY) + marginTop, textPaint);
 }
  @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;
  }
Example #11
0
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
   if (IsPaint) canvas.drawPath(mPath, mPaint);
   else canvas.drawPath(mPath, mEraserPaint);
 }
Example #12
0
  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);
  }
    public DrawView(Context context) {
      super(context);

      rect = new Rect(0, 0, 100, 100);
      rect1 = new Rect(0, 0, 500, 200);
      p = new Paint(Paint.ANTI_ALIAS_FLAG);
      picture = new Picture();

      Canvas canvas = picture.beginRecording(300, 300);

      p.setColor(Color.GREEN);
      canvas.drawCircle(150, 100, 80, p);

      p.setColor(Color.BLUE);
      canvas.drawRect(20, 70, 150, 200, p);

      p.setColor(Color.RED);
      path = new Path();
      path.moveTo(170, 80);
      path.lineTo(240, 210);
      path.lineTo(100, 210);
      path.close();
      canvas.drawPath(path, p);

      picture.endRecording();
    }
Example #14
0
 private void refresh(Canvas canvas, Paint p) {
   String s = sharedPrefs.getString("list", "-1");
   if ((s.equals("2")) && (ColorTheme.isLightTheme)) {
     ColorTheme.setDarkTheme();
   } else if ((s.equals("1") && (ColorTheme.isDarkTheme))) {
     ColorTheme.setLightTheme();
   }
   if (!coordinateSystemCreated) {
     setSystemInformation();
     coordinateSystem = new CoordinateSystem();
     coordinateSystemCreated = true;
   }
   canvas.drawColor(ColorTheme.DARK_COLOR);
   paint.setStrokeWidth(4);
   for (ShapeList shape : shapes) {
     shape.draw(canvas, p);
     if (paint.getStrokeWidth() == 4) {
       paint.setStrokeWidth(1);
     }
   }
   if (shapes.size() != 0) {
     paint.setStrokeWidth(4);
     shapes.get(FIRST_SHAPE_IN_LIST).draw(canvas, paint);
   }
   if (shapes.size() > 0) {
     canvas.drawText(shapes.get(FIRST_SHAPE_IN_LIST).toString(), 30, 15, p);
   }
   if (sharedPrefs.getBoolean("checkBox", false)) {
     coordinateSystem.draw(canvas);
   }
 }
Example #15
0
 private void drawIntoBitmap() {
   Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
   if (mAlpha) {
     if (!mBlur) {
       mViewBitmap.eraseColor(Color.TRANSPARENT);
     }
   }
   if (mBlur) {
     if (mAlphaMark) {
       p.setAlpha(mBlurVal);
     } else {
       mAlphaMark = true;
     }
   }
   Canvas c = new Canvas(mViewBitmap);
   c.save();
   Path path = new Path();
   path.moveTo(0, 0);
   path.arcTo(
       new RectF(-mBitmapViewWidth, -mBitmapViewWidth, mBitmapViewWidth, mBitmapViewWidth),
       0,
       mAngle);
   // path.lineTo(0, 1);
   path.close();
   c.clipPath(path);
   // c.drawRGB(0, 0, 0);
   // RectF r = new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight);
   c.drawBitmap(
       mBitmap,
       new Rect(mCurX, mCurY, mRadius + mCurX, mBitmapNewHeight + mCurY),
       new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight),
       p);
 }
Example #16
0
 @Override
 protected void onDraw(Canvas canvas) {
   // TODO Auto-generated method stub
   super.onDraw(canvas);
   Matrix matrix = new Matrix();
   Paint paint = new Paint();
   float x;
   if (onSlip) {
     if (nowX >= bg_on.getWidth()) {
       x = bg_on.getWidth() - slip_btn.getWidth() / 2;
     } else {
       x = nowX - slip_btn.getWidth() / 2;
     }
   } else {
     if (nowChoose) {
       x = btn_On.left;
     } else {
       x = btn_Off.left;
     }
   }
   if (nowX < (bg_on.getWidth() / 2)) {
     canvas.drawBitmap(bg_off, matrix, paint);
   } else {
     canvas.drawBitmap(bg_on, matrix, paint);
   }
   if (x < 0) {
     x = 0;
   } else if (x > bg_on.getWidth() - slip_btn.getWidth()) {
     x = bg_on.getWidth() - slip_btn.getWidth();
   }
   canvas.drawBitmap(slip_btn, x, 0, paint);
 }
Example #17
0
 private void drawIntoBitmap(int i) {
   Canvas c = new Canvas(mViewBitmap);
   // Paint p = new Paint();
   Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
   if (mBlur) {
     if (mAlphaMark) {
       p.setAlpha(mBlurVal);
     } else {
       mAlphaMark = true;
     }
   }
   // p.setAntiAlias(true);
   c.save();
   Path path = new Path();
   path.moveTo(0, 0);
   path.arcTo(
       new RectF(-mBitmapViewWidth, -mBitmapViewWidth, mBitmapViewWidth, mBitmapViewWidth),
       0,
       mAngle);
   // path.lineTo(0, 1);
   path.close();
   c.clipPath(path);
   // RectF r = new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight);
   c.drawBitmap(
       mBitmap,
       new Rect(mCurX, mCurY, mRadius + mCurX, mBitmapNewHeight + mCurY),
       new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight),
       p);
   // mPaint.setTextSize(28);
   // mPaint.setColor(Color.RED);
   // c.drawText(debugString, 150, 50, mPaint);
 }
  // ==============================================================================
  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 = 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;
  }
Example #19
0
    @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);
    }
  @SuppressLint("DrawAllocation")
  @Override
  public void onDraw(Canvas canvas) {
    // load the bitmap
    loadBitmap();

    // init shader
    if (image != null) {
      shader =
          new BitmapShader(
              Bitmap.createScaledBitmap(image, canvas.getWidth(), canvas.getHeight(), false),
              Shader.TileMode.CLAMP,
              Shader.TileMode.CLAMP);
      paint.setShader(shader);
      int circleCenter = viewWidth / 2;

      // circleCenter is the x or y of the view's center
      // radius is the radius in pixels of the cirle to be drawn
      // paint contains the shader that will texture the shape
      canvas.drawCircle(
          circleCenter + borderWidth,
          circleCenter + borderWidth,
          circleCenter + borderWidth,
          paintBorder);
      canvas.drawCircle(
          circleCenter + borderWidth, circleCenter + borderWidth, circleCenter, paint);
    }
  }
Example #21
0
 protected void onDraw(Canvas paramCanvas) {
   Drawable localDrawable = getDrawable();
   if (localDrawable == null) return;
   try {
     if (this.paint == null) {
       Paint localPaint1 = new Paint();
       this.paint = localPaint1;
       this.paint.setFilterBitmap(false);
       Paint localPaint2 = this.paint;
       Xfermode localXfermode1 = MASK_XFERMODE;
       @SuppressWarnings("unused")
       Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1);
     }
     float f1 = getWidth();
     float f2 = getHeight();
     int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, 31);
     int j = getWidth();
     int k = getHeight();
     localDrawable.setBounds(0, 0, j, k);
     localDrawable.draw(paramCanvas);
     if ((this.mask == null) || (this.mask.isRecycled())) {
       Bitmap localBitmap1 = createMask();
       this.mask = localBitmap1;
     }
     Bitmap localBitmap2 = this.mask;
     Paint localPaint3 = this.paint;
     paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3);
     paramCanvas.restoreToCount(i);
     return;
   } catch (Exception localException) {
     StringBuilder localStringBuilder =
         new StringBuilder().append("Attempting to draw with recycled bitmap. View ID = ");
     System.out.println("localStringBuilder==" + localStringBuilder);
   }
 }
  @Override
  public void onStart() {
    super.onStart();

    TouchImageView mapPanView =
        (TouchImageView) getActivity().findViewById(R.id.TrailBreakdownView);
    // set max zoom a user can zoom into the map when double tapping or
    // pinching
    mapPanView.setMaxZoom(10);

    Bitmap bitmap1 =
        BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.trails_breakdown);

    Bitmap drawnBitmap = null;

    try {
      drawnBitmap = Bitmap.createBitmap(1447, 1966, Bitmap.Config.RGB_565);

      // canvas for painting onto the map view
      Canvas canvas = new Canvas(drawnBitmap);
      // JUST CHANGE TO DIFFERENT Bitmaps and coordinates .
      int mapX = 0;
      int mapY = 0;
      int mapWidth = 1447;
      int mapHeight = 1966;
      canvas.drawBitmap(bitmap1, null, new Rect(mapX, mapY, mapWidth, mapHeight), null);

    } catch (Exception e) {
      e.printStackTrace();
    }

    // first map has no points marked
    mapPanView.setImageBitmap(drawnBitmap);
  }
  @Override
  protected void onDraw(Canvas canvas) {
    final int height = getHeight();
    final int childCount = getChildCount();
    final SlidingTabLayout.TabColorizer tabColorizer =
        mCustomTabColorizer != null ? mCustomTabColorizer : mDefaultTabColorizer;

    // Thick colored underline below the current selection
    if (childCount > 0) {
      View selectedTitle = getChildAt(mSelectedPosition);
      int left = selectedTitle.getLeft();
      int right = selectedTitle.getRight();
      int color = tabColorizer.getIndicatorColor(mSelectedPosition);

      if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
        int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
        if (color != nextColor) {
          color = blendColors(nextColor, color, mSelectionOffset);
        }

        // Draw the selection partway between the tabs
        View nextTitle = getChildAt(mSelectedPosition + 1);
        left = (int) (mSelectionOffset * nextTitle.getLeft() + (1.0f - mSelectionOffset) * left);
        right = (int) (mSelectionOffset * nextTitle.getRight() + (1.0f - mSelectionOffset) * right);
      }

      mSelectedIndicatorPaint.setColor(color);

      canvas.drawRect(
          left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint);
    }

    // Thin underline along the entire bottom edge
    canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);
  }
Example #24
0
  public static Bitmap doHighlightImage(Bitmap src) {
    // create new bitmap, which will be painted and becomes result image
    Bitmap bmOut =
        Bitmap.createBitmap(src.getWidth() + 96, src.getHeight() + 96, Bitmap.Config.ARGB_8888);
    // setup canvas for painting
    Canvas canvas = new Canvas(bmOut);
    // setup default color
    canvas.drawColor(0, PorterDuff.Mode.CLEAR);

    // create a blur paint for capturing alpha
    Paint ptBlur = new Paint();
    ptBlur.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL));
    int[] offsetXY = new int[2];
    // capture alpha into a bitmap
    Bitmap bmAlpha = src.extractAlpha(ptBlur, offsetXY);
    // create a color paint
    Paint ptAlphaColor = new Paint();
    ptAlphaColor.setColor(0xFFFFFFFF);
    // paint color for captured alpha region (bitmap)
    canvas.drawBitmap(bmAlpha, offsetXY[0], offsetXY[1], ptAlphaColor);
    // free memory
    bmAlpha.recycle();

    // paint the image source
    canvas.drawBitmap(src, 0, 0, null);

    // return out final image
    return bmOut;
  }
 @Override
 public void onDraw(Canvas canvas) {
   float alpha = 1;
   if (mXFade != null) {
     alpha = mXFade.getValue();
   } else if (mFadeIn != null) {
     alpha = mFadeIn.getValue();
   }
   int state = canvas.save();
   if (mFadeIn != null) {
     float sf = 0.9f + alpha * 0.1f;
     canvas.scale(sf, sf, mCenter.x, mCenter.y);
   }
   drawFocus(canvas);
   if (mState == STATE_FINISHING) {
     canvas.restoreToCount(state);
     return;
   }
   if ((mOpenItem == null) || (mXFade != null)) {
     // draw base menu
     for (PieItem item : mItems) {
       drawItem(canvas, item, alpha);
     }
   }
   if (mOpenItem != null) {
     for (PieItem inner : mOpenItem.getItems()) {
       drawItem(canvas, inner, (mXFade != null) ? (1 - 0.5f * alpha) : 1);
     }
   }
   canvas.restoreToCount(state);
 }
  protected void drawResultPoints(Bitmap barcode, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
      Canvas canvas = new Canvas(barcode);
      Paint paint = new Paint();
      paint.setColor(getResources().getColor(R.color.result_image_border));
      paint.setStrokeWidth(3.0f);
      paint.setStyle(Paint.Style.STROKE);
      Rect border = new Rect(2, 2, barcode.getWidth() - 2, barcode.getHeight() - 2);
      canvas.drawRect(border, paint);

      paint.setColor(getResources().getColor(R.color.result_points));
      if (points.length == 2) {
        paint.setStrokeWidth(4.0f);
        drawLine(canvas, paint, points[0], points[1]);
      } else if (points.length == 4
          && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A
              || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
        // Hacky special case -- draw two lines, for the barcode and
        // metadata
        drawLine(canvas, paint, points[0], points[1]);
        drawLine(canvas, paint, points[2], points[3]);
      } else {
        paint.setStrokeWidth(10.0f);
        for (ResultPoint point : points) {
          canvas.drawPoint(point.getX(), point.getY(), paint);
        }
      }
    }
  }
  /**
   * 将图片转化为圆形头像 @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;
  }
Example #28
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (currentMessageObject == null) {
      return;
    }

    if (currentMessageObject.isOutOwner()) {
      timePaint.setColor(theme.ChatMusicCell_timePaint_color);
    } else {
      timePaint.setColor(theme.ChatMusicCell_timePaint_color_2);
    }
    radialProgress.draw(canvas);

    canvas.save();
    canvas.translate(timeX + titleX, AndroidUtilities.dp(12) + namesOffset);
    titleLayout.draw(canvas);
    canvas.restore();

    canvas.save();
    if (MediaController.getInstance().isPlayingAudio(currentMessageObject)) {
      canvas.translate(seekBarX, seekBarY);
      seekBar.draw(canvas);
    } else {
      canvas.translate(timeX + authorX, AndroidUtilities.dp(32) + namesOffset);
      authorLayout.draw(canvas);
    }
    canvas.restore();

    canvas.save();
    canvas.translate(timeX, AndroidUtilities.dp(52) + namesOffset);
    timeLayout.draw(canvas);
    canvas.restore();
  }
Example #29
0
  private void blur(Bitmap bg, View view) {
    long startMs = System.currentTimeMillis();

    float radius = 20;
    Bitmap overlay =
        Bitmap.createBitmap(
            view.getMeasuredWidth() / scaleFactor,
            view.getMeasuredHeight() / scaleFactor,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    // scale参数为float类型
    canvas.scale(1.0f / scaleFactor, 1.0f / scaleFactor);
    // 开启双缓冲
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);

    canvas.drawBitmap(bg, 0, 0, paint);
    // Bitmap result = blurBitmap(overlay, 2);
    Bitmap result = blurBitmapStack(overlay, 2);
    view.setBackground(new BitmapDrawable(result));
    long endMs = System.currentTimeMillis();
    String time = (endMs - startMs) + "ms";
    Toast.makeText(this, time, Toast.LENGTH_SHORT).show();
  }
Example #30
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    if (mShowcaseX < 0 || mShowcaseY < 0 || mIsRedundant) {
      super.dispatchDraw(canvas);
      return;
    }

    boolean recalculatedCling = mShowcaseDrawer.calculateShowcaseRect(mShowcaseX, mShowcaseY);
    boolean recalculateText = recalculatedCling || mAlteredText;
    mAlteredText = false;

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && !mHasNoTarget) {
      Path path = new Path();
      path.addCircle(mShowcaseX, mShowcaseY, mShowcaseRadius, Path.Direction.CW);
      canvas.clipPath(path, Op.DIFFERENCE);
    }

    // Draw background color
    canvas.drawColor(mBackgroundColor);

    // Draw the showcase drawable
    if (!mHasNoTarget) {
      mShowcaseDrawer.drawShowcase(
          canvas, mShowcaseX, mShowcaseY, mScaleMultiplier, mShowcaseRadius);
    }

    // Draw the text on the screen, recalculating its position if necessary
    if (recalculateText) {
      mTextDrawer.calculateTextPosition(canvas.getWidth(), canvas.getHeight(), this);
    }
    mTextDrawer.draw(canvas, recalculateText);

    super.dispatchDraw(canvas);
  }