コード例 #1
0
    public NormalBatteryMeterDrawable(Resources res, boolean horizontal) {
      super();
      mHorizontal = horizontal;
      mDisposed = false;

      mFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mFramePaint.setColor(res.getColor(R.color.batterymeter_frame_color));
      mFramePaint.setDither(true);
      mFramePaint.setStrokeWidth(0);
      mFramePaint.setStyle(Paint.Style.FILL_AND_STROKE);
      mFramePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));

      mBatteryPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mBatteryPaint.setDither(true);
      mBatteryPaint.setStrokeWidth(0);
      mBatteryPaint.setStyle(Paint.Style.FILL_AND_STROKE);

      mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mTextPaint.setColor(res.getColor(R.color.batterymeter_bolt_color));
      Typeface font = Typeface.create("sans-serif-condensed", Typeface.BOLD);
      mTextPaint.setTypeface(font);
      mTextPaint.setTextAlign(Paint.Align.CENTER);

      mWarningTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mWarningTextPaint.setColor(mColors[1]);
      font = Typeface.create("sans-serif", Typeface.BOLD);
      mWarningTextPaint.setTypeface(font);
      mWarningTextPaint.setTextAlign(Paint.Align.CENTER);

      mBoltPaint = new Paint();
      mBoltPaint.setAntiAlias(true);
      mBoltPaint.setColor(res.getColor(R.color.batterymeter_bolt_color));
      mBoltPoints = loadBoltPoints(res);
    }
コード例 #2
0
  public CircleProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    pathPaint = new Paint();
    // 设置是否抗锯齿
    pathPaint.setAntiAlias(true);
    // 帮助消除锯齿
    pathPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    // 设置中空的样式
    pathPaint.setStyle(Paint.Style.STROKE);
    pathPaint.setDither(true);
    pathPaint.setStrokeJoin(Paint.Join.ROUND);

    fillArcPaint = new Paint();
    // 设置是否抗锯齿
    fillArcPaint.setAntiAlias(true);
    // 帮助消除锯齿
    fillArcPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    // 设置中空的样式
    fillArcPaint.setStyle(Paint.Style.STROKE);
    fillArcPaint.setDither(true);
    fillArcPaint.setStrokeJoin(Paint.Join.ROUND);

    oval = new RectF();
    emboss = new EmbossMaskFilter(direction, light, specular, blur);
    mBlur = new BlurMaskFilter(20, BlurMaskFilter.Blur.NORMAL);
    anim = new BarAnimation();
  }
コード例 #3
0
ファイル: MapGoogleActivity.java プロジェクト: bosicc/kpi
    public void draw(Canvas canvas, MapView mapv, boolean shadow) {
      int cZoom = mapView.getZoomLevel();
      GeoPoint kpGP = parceToGP(r.getString(R.string.kpiPoint));
      // Log.i(TAG, "Zoom=" + cZoom);

      if (cZoom > mZoomMin) {

        GeoPoint[] kpiZone0 = parceToGPAr(r.getStringArray(R.array.kpiZone0));

        Paint mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(0xff0962f5);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);
        drawFigure(mPaint, canvas, shadow, kpiZone0);

        if (cZoom > mZoomMax) {
          super.draw(canvas, mapv, false);

          int i;
          Point p = new Point();
          Paint tPaint = new Paint();

          tPaint.setDither(true);
          tPaint.setColor(Color.BLACK);
          tPaint.setStyle(Paint.Style.FILL);
          tPaint.setFakeBoldText(true);
          tPaint.setTextAlign(Align.CENTER);
          tPaint.setTextSize(14);

          for (mapItem item : itemAr) {
            projection.toPixels(item.gp, p);
            canvas.drawText(item.index, p.x, p.y, tPaint);
          }
        } else { // Draw only KPI Area
          int i;
          Point p = new Point();
          Paint tPaint = new Paint();

          tPaint.setDither(true);
          tPaint.setColor(0xff0962f5);
          tPaint.setStyle(Paint.Style.FILL);
          tPaint.setFakeBoldText(true);
          tPaint.setTextAlign(Align.CENTER);
          tPaint.setTextSize(18);

          projection.toPixels(kpGP, p);
          canvas.drawText("KPI", p.x, p.y, tPaint);
          canvas.drawBitmap(
              kpiIcon, p.x - kpiIcon.getWidth() / 2, p.y - kpiIcon.getHeight() / 2, null);
        }
      } else {
        Point p = new Point();
        projection.toPixels(kpGP, p);
        canvas.drawBitmap(
            kpiIcon, p.x - kpiIcon.getWidth() / 2, p.y - kpiIcon.getHeight() / 2, null);
      }
    }
コード例 #4
0
    public CircleBatteryMeterDrawable(Resources res) {
      super();
      mDisposed = false;

      mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mTextPaint.setColor(res.getColor(R.color.status_bar_clock_color));
      Typeface font = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
      mTextPaint.setTypeface(font);
      mTextPaint.setTextAlign(Paint.Align.CENTER);

      mFrontPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mFrontPaint.setStrokeCap(Paint.Cap.BUTT);
      mFrontPaint.setDither(true);
      mFrontPaint.setStrokeWidth(0);
      mFrontPaint.setStyle(Paint.Style.STROKE);
      mFrontPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));

      mBackPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mBackPaint.setColor(res.getColor(R.color.batterymeter_frame_color));
      mBackPaint.setStrokeCap(Paint.Cap.BUTT);
      mBackPaint.setDither(true);
      mBackPaint.setStrokeWidth(0);
      mBackPaint.setStyle(Paint.Style.STROKE);
      mBackPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));

      mBoltPaint = new Paint();
      mBoltPaint.setAntiAlias(true);
      mBoltPaint.setColor(getColorForLevel(50));
      mBoltPoints = loadBoltPoints(res);
    }
コード例 #5
0
ファイル: ColorPicker.java プロジェクト: huanting/StudyVG
  private void init() {

    colorPointerPaint = new Paint();
    colorPointerPaint.setStyle(Style.STROKE);
    colorPointerPaint.setStrokeWidth(2f);
    colorPointerPaint.setARGB(128, 0, 0, 0);

    valuePointerPaint = new Paint();
    valuePointerPaint.setStyle(Style.STROKE);
    valuePointerPaint.setStrokeWidth(2f);

    valuePointerArrowPaint = new Paint();

    colorWheelPaint = new Paint();
    colorWheelPaint.setAntiAlias(true);
    colorWheelPaint.setDither(true);

    valueSliderPaint = new Paint();
    valueSliderPaint.setAntiAlias(true);
    valueSliderPaint.setDither(true);

    colorViewPaint = new Paint();
    colorViewPaint.setAntiAlias(true);

    colorViewPath = new Path();
    valueSliderPath = new Path();
    arrowPointerPath = new Path();

    outerWheelRect = new RectF();
    innerWheelRect = new RectF();

    colorPointerCoords = new RectF();
  }
コード例 #6
0
ファイル: DrawView.java プロジェクト: raufridzuan/carat
  public DrawView(Context context) {
    super(context);
    axisPaint.setDither(true);
    axisPaint.setStyle(Paint.Style.STROKE);
    axisPaint.setStrokeJoin(Paint.Join.ROUND);
    axisPaint.setStrokeCap(Paint.Cap.ROUND);
    axisPaint.setColor(getContext().getResources().getColor(R.color.text));
    axisPaint.setStrokeWidth(strokeWidth);

    withPaint.setDither(true);
    withPaint.setStyle(Paint.Style.STROKE);
    withPaint.setStrokeJoin(Paint.Join.ROUND);
    withPaint.setStrokeCap(Paint.Cap.ROUND);
    withPaint.setColor(getContext().getResources().getColor(R.color.with));
    withPaint.setStrokeWidth(strokeWidth);

    withTextPaint.setColor(getContext().getResources().getColor(R.color.with));
    withTextPaint.setTextSize(TEXT_SIZE);
    withTextPaint.setTextAlign(Align.RIGHT);

    withoutPaint.setDither(true);
    withoutPaint.setStyle(Paint.Style.STROKE);
    withoutPaint.setStrokeJoin(Paint.Join.ROUND);
    withoutPaint.setStrokeCap(Paint.Cap.ROUND);
    withoutPaint.setColor(getContext().getResources().getColor(R.color.without));
    withoutPaint.setStrokeWidth(strokeWidth);

    withoutTextPaint.setColor(getContext().getResources().getColor(R.color.without));
    withoutTextPaint.setTextSize(TEXT_SIZE);
    withoutTextPaint.setTextAlign(Align.RIGHT);

    textPaint.setColor(getContext().getResources().getColor(R.color.text));
    textPaint.setTextSize(TEXT_SIZE);
  }
コード例 #7
0
ファイル: OvalShadowDrawable.java プロジェクト: bolig/pSchool
  private void buildShadow() {
    if (mShadowSize <= 0) return;

    if (mShadowPaint == null) {
      mShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
      mShadowPaint.setStyle(Paint.Style.FILL);
      mShadowPaint.setDither(true);
    }
    float startRatio = (float) mRadius / (mRadius + mShadowSize + mShadowOffset);
    mShadowPaint.setShader(
        new RadialGradient(
            0,
            0,
            mRadius + mShadowSize,
            new int[] {COLOR_SHADOW_START, COLOR_SHADOW_START, COLOR_SHADOW_END},
            new float[] {0f, startRatio, 1f},
            Shader.TileMode.CLAMP));

    if (mShadowPath == null) {
      mShadowPath = new Path();
      mShadowPath.setFillType(Path.FillType.EVEN_ODD);
    } else mShadowPath.reset();
    float radius = mRadius + mShadowSize;
    mTempRect.set(-radius, -radius, radius, radius);
    mShadowPath.addOval(mTempRect, Path.Direction.CW);
    radius = mRadius - 1;
    mTempRect.set(-radius, -radius - mShadowOffset, radius, radius - mShadowOffset);
    mShadowPath.addOval(mTempRect, Path.Direction.CW);

    if (mGlowPaint == null) {
      mGlowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
      mGlowPaint.setStyle(Paint.Style.FILL);
      mGlowPaint.setDither(true);
    }
    startRatio = (mRadius - mShadowSize / 2f) / (mRadius + mShadowSize / 2f);
    mGlowPaint.setShader(
        new RadialGradient(
            0,
            0,
            mRadius + mShadowSize / 2f,
            new int[] {COLOR_SHADOW_START, COLOR_SHADOW_START, COLOR_SHADOW_END},
            new float[] {0f, startRatio, 1f},
            Shader.TileMode.CLAMP));

    if (mGlowPath == null) {
      mGlowPath = new Path();
      mGlowPath.setFillType(Path.FillType.EVEN_ODD);
    } else mGlowPath.reset();

    radius = mRadius + mShadowSize / 2f;
    mTempRect.set(-radius, -radius, radius, radius);
    mGlowPath.addOval(mTempRect, Path.Direction.CW);
    radius = mRadius - 1;
    mTempRect.set(-radius, -radius, radius, radius);
    mGlowPath.addOval(mTempRect, Path.Direction.CW);
  }
コード例 #8
0
ファイル: CircularSeekBar.java プロジェクト: Ratufa/notarius
  /** Initializes the {@code Paint} objects with the appropriate styles. */
  protected void initPaints() {
    mCirclePaint = new Paint();
    mCirclePaint.setAntiAlias(true);
    mCirclePaint.setDither(true);
    mCirclePaint.setColor(mCircleColor);
    mCirclePaint.setStrokeWidth(mCircleStrokeWidth);
    mCirclePaint.setStyle(Paint.Style.STROKE);
    mCirclePaint.setStrokeJoin(Paint.Join.ROUND);
    mCirclePaint.setStrokeCap(Paint.Cap.ROUND);

    mCircleFillPaint = new Paint();
    mCircleFillPaint.setAntiAlias(true);
    mCircleFillPaint.setDither(true);
    mCircleFillPaint.setColor(mCircleFillColor);
    mCircleFillPaint.setStyle(Paint.Style.FILL);

    mCircleProgressPaint = new Paint();
    mCircleProgressPaint.setAntiAlias(true);
    mCircleProgressPaint.setDither(true);
    mCircleProgressPaint.setColor(mCircleProgressColor);
    mCircleProgressPaint.setStrokeWidth(mCircleStrokeWidth);
    mCircleProgressPaint.setStyle(Paint.Style.STROKE);
    mCircleProgressPaint.setStrokeJoin(Paint.Join.ROUND);
    mCircleProgressPaint.setStrokeCap(Paint.Cap.ROUND);

    mCircleProgressGlowPaint = new Paint();
    mCircleProgressGlowPaint.set(mCircleProgressPaint);
    mCircleProgressGlowPaint.setMaskFilter(
        new BlurMaskFilter((5f * DPTOPX_SCALE), BlurMaskFilter.Blur.NORMAL));

    mPointerPaint = new Paint();
    mPointerPaint.setAntiAlias(true);
    mPointerPaint.setDither(true);
    mPointerPaint.setStyle(Paint.Style.FILL);
    mPointerPaint.setColor(mPointerColor);
    mPointerPaint.setStrokeWidth(mPointerRadius);

    mPointerHaloPaint = new Paint();
    mPointerHaloPaint.set(mPointerPaint);
    mPointerHaloPaint.setColor(mPointerHaloColor);
    mPointerHaloPaint.setAlpha(mPointerAlpha);
    mPointerHaloPaint.setStrokeWidth(mPointerRadius + mPointerHaloWidth);

    mPointerHaloBorderPaint = new Paint();
    mPointerHaloBorderPaint.set(mPointerPaint);
    mPointerHaloBorderPaint.setStrokeWidth(mPointerHaloBorderWidth);
    mPointerHaloBorderPaint.setStyle(Paint.Style.STROKE);
  }
コード例 #9
0
  public static Bitmap getRoundedBitmap(Bitmap src, int radius) {
    Bitmap roundBitmap;
    roundBitmap =
        (src.getWidth() == radius || src.getHeight() == radius)
            ? src
            : Bitmap.createScaledBitmap(src, radius, radius, false);
    Bitmap des =
        Bitmap.createBitmap(
            roundBitmap.getWidth(), roundBitmap.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(des);
    final Rect rect = new Rect(0, 0, des.getWidth(), des.getHeight());

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);

    canvas.drawARGB(0, 0, 0, 0);

    paint.setColor(Color.parseColor("#BAB399"));

    canvas.drawCircle(
        des.getWidth() / 2 + 0.7f, des.getHeight() / 2 + 0.7f, des.getWidth() / 2 - 10f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(roundBitmap, rect, rect, paint);

    return des;
  }
コード例 #10
0
  private Bitmap tintImage(Bitmap image, Bitmap image2, KrollDict args) {
    String col = args.optString("color", "");
    String mod1 = args.optString("modeColor", "multiply");
    String mod2 = args.optString("modeImage", "multiply");
    Boolean grad = args.optBoolean("vignette", false);

    if (image != null) {

      Mode filterMode1 = getFilter(mod1);
      Mode filterMode2 = getFilter(mod2);
      int width = image.getWidth();
      int height = image.getHeight();

      Bitmap workingBitmap = Bitmap.createScaledBitmap(image, width, height, true);
      Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
      Canvas canvas = new Canvas(mutableBitmap);

      Bitmap resultBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
      Canvas canvas2 = new Canvas(resultBitmap);

      // add second image
      if (image2 != null) {
        Paint Compose = new Paint();
        Compose.setXfermode(
            new PorterDuffXfermode(filterMode2)); // KAI: fixed error in the original code
        canvas.drawBitmap(image2, 0, 0, Compose);
      }

      Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

      // add color filter
      if (col != "") {
        PorterDuffColorFilter cf =
            new PorterDuffColorFilter(
                Color.parseColor(col), filterMode1); // KAI: fixed error in the original code
        paint.setColorFilter(cf);
      }

      // gradient
      if (grad) {
        int[] Colors = {0x00000000, 0xFF000000};
        float[] ColorPosition = {0.10f, 0.99f};
        RadialGradient gradient =
            new RadialGradient(
                width / 2,
                height / 2,
                width - width / 2,
                Colors,
                ColorPosition,
                android.graphics.Shader.TileMode.CLAMP);
        paint.setDither(true);
        paint.setShader(gradient);
      }

      canvas2.drawBitmap(mutableBitmap, 0, 0, paint);
      return resultBitmap;
    }

    return null;
  }
コード例 #11
0
  public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;

    if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
      float smallest = Math.min(bmp.getWidth(), bmp.getHeight());
      float factor = smallest / radius;
      sbmp =
          Bitmap.createScaledBitmap(
              bmp, (int) (bmp.getWidth() / factor), (int) (bmp.getHeight() / factor), false);
    } else {
      sbmp = bmp;
    }

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

    final int color = 0xffa19774;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, radius, radius);

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#FFFFFF"));
    canvas.drawCircle(radius / 2, radius / 2, radius / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    return output;
  }
コード例 #12
0
ファイル: DrawPic.java プロジェクト: wudizhangzhi/test
  public DrawPic(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = context;

    clr_bg = Color.WHITE;
    clr_fg = Color.CYAN;

    mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(3);
    mPaint.setColor(clr_fg);
    //		mPaint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    path = new Path();

    imagebitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.applog);

    cacheBitmap = Bitmap.createBitmap(480, 480, Config.ARGB_8888);

    cacheCanvas = new Canvas(cacheBitmap);
    //		cacheCanvas.drawBitmap(cacheBitmap, null, null);
    //		image.setBounds(0, 0, 180, 180);
    //		image.draw(cacheCanvas);

  }
コード例 #13
0
  @SuppressLint("DrawAllocation")
  @Override
  protected void onDraw(Canvas canvas) {

    Drawable drawable = getDrawable();

    if (drawable == null) {
      return;
    }

    if (getWidth() == 0 || getHeight() == 0) {
      return;
    }
    Bitmap b = ((BitmapDrawable) drawable).getBitmap();
    Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);

    int w = getWidth(), h = getHeight();

    Bitmap roundBitmap = getCroppedBitmap(bitmap, w);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    paint.setColor(color);
    // paint.setXfermode( new PorterDuffXfermode( Mode.SRC_IN ) );
    canvas.drawCircle(w / 2, w / 2, w / 2, paint);

    canvas.drawBitmap(roundBitmap, 0, 0, null);
  }
コード例 #14
0
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    Point current = new Point();
    Path path = new Path();
    Projection projection = mapView.getProjection();
    Iterator<GeoPoint> iterator = pointList.iterator();

    if (iterator.hasNext()) {
      projection.toPixels(iterator.next(), current);
      path.moveTo((float) current.x, (float) current.y);
    } else return;

    while (iterator.hasNext()) {
      projection.toPixels(iterator.next(), current);
      path.lineTo((float) current.x, (float) current.y);
    }

    Paint pathPaint = new Paint();
    pathPaint.setAntiAlias(true);
    pathPaint.setDither(true);
    pathPaint.setStrokeWidth(3.5f);
    pathPaint.setColor(Color.rgb(15, 200, 2));
    pathPaint.setStyle(Style.STROKE);
    canvas.drawPath(path, pathPaint);
  }
コード例 #15
0
 public Paint getPaint() {
   if (mPaint == null) {
     mPaint = new Paint();
     mPaint.setDither(DEFAULT_DITHER);
   }
   return mPaint;
 }
コード例 #16
0
  public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;
    if (bmp.getWidth() != radius || bmp.getHeight() != radius)
      sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    else sbmp = bmp;
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

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

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 255, 255, 255);
    paint.setColor(Color.parseColor("#7f97d2"));
    canvas.drawCircle(
        sbmp.getWidth() / 2 + 0.7f,
        sbmp.getHeight() / 2 + 0.7f,
        sbmp.getWidth() / 2 - strokeWidth,
        paint); // 2-9f
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    //        Paint pTouch = new Paint(Paint.ANTI_ALIAS_FLAG);
    //	    pTouch.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    //	    pTouch.setAlpha(255);
    //	    pTouch.setColor(Color.TRANSPARENT);
    //	    pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));

    //	    canvas.drawCircle(sbmp.getWidth() / 2-.6f, sbmp.getHeight() / 2, ((float)
    // Math.ceil((sbmp.getHeight()+15)/11))+.2f, pTouch);
    //	    canvas.drawCircle(sbmp.getWidth() / 2-.6f, sbmp.getHeight() / 2, 57, pTouch);
    return output;
  }
コード例 #17
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;
  }
コード例 #18
0
    public SampleView(Context context) {
      super(context);
      setFocusable(true);

      mColors = createColors();
      int[] colors = mColors;

      mBitmaps = new Bitmap[6];
      // these three are initialized with colors[]
      mBitmaps[0] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
      mBitmaps[1] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.RGB_565);
      mBitmaps[2] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT, Bitmap.Config.ARGB_4444);

      // these three will have their colors set later
      mBitmaps[3] = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
      mBitmaps[4] = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.RGB_565);
      mBitmaps[5] = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_4444);
      for (int i = 3; i <= 5; i++) {
        mBitmaps[i].setPixels(colors, 0, STRIDE, 0, 0, WIDTH, HEIGHT);
      }

      mPaint = new Paint();
      mPaint.setDither(true);

      // now encode/decode using JPEG and PNG
      mJPEG = new Bitmap[mBitmaps.length];
      mPNG = new Bitmap[mBitmaps.length];
      for (int i = 0; i < mBitmaps.length; i++) {
        mJPEG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.JPEG, 80);
        mPNG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.PNG, 0);
      }
    }
コード例 #19
0
 public static Paint createBitmapPaint() {
   Paint paint = new Paint();
   paint.setDither(true);
   paint.setFilterBitmap(true);
   paint.setAntiAlias(true);
   return paint;
 }
コード例 #20
0
ファイル: BitmapTool.java プロジェクト: huxin-89/AllInOne
  /**
   * @param bmp
   * @param radius
   * @return
   */
  public static Bitmap getCroppedBitmap(Bitmap bmp, float radius) {
    Bitmap sbmp;
    int width = (int) radius;
    if (bmp.getWidth() != width || bmp.getHeight() != width) {
      sbmp = Bitmap.createScaledBitmap(bmp, width, width, false);
    } else {
      sbmp = bmp;
    }
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

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

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(
        sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);
    return output;
  }
コード例 #21
0
 public static void previous(
     Canvas paramCanvas, Paint paramPaint, int paramInt1, int paramInt2, int paramInt3) {
   Path localPath = new Path();
   float f1 = paramInt1 - paramInt3 * 2.0F;
   float f2 = paramInt2 - paramInt3 * 2.0F;
   float f3 = f1 / 10.0F;
   Paint localPaint = new Paint();
   localPaint.setDither(true);
   localPaint.setColor(paramPaint.getColor());
   localPaint.setStyle(Paint.Style.STROKE);
   localPaint.setStrokeWidth(f3);
   float f4 = paramInt3;
   float f5 = f3 / 2.0F;
   float f6 = paramInt3;
   float f7 = paramInt3;
   paramCanvas.drawLine(f5 + f4, f6, f3 / 2.0F + f7, paramInt3 + f2, localPaint);
   localPath.moveTo(paramInt3 + f3, paramInt3 + f2 / 2.0F);
   localPath.lineTo(paramInt3 + f3 + (f1 - f3) / 2.0F, paramInt3);
   localPath.lineTo(paramInt3 + f3 + (f1 - f3) / 2.0F, paramInt3 + f2);
   localPath.lineTo(paramInt3 + f3, paramInt3 + f2 / 2.0F);
   localPath.moveTo(paramInt3 + f3 + (f1 - f3) / 2.0F, paramInt3 + f2 / 2.0F);
   localPath.lineTo(paramInt3 + f1, paramInt3);
   localPath.lineTo(paramInt3 + f1, paramInt3 + f2);
   localPath.lineTo(paramInt3 + f3 + (f1 - f3) / 2.0F, paramInt3 + f2 / 2.0F);
   paramCanvas.drawPath(localPath, paramPaint);
 }
コード例 #22
0
 public static void next(
     Canvas paramCanvas, Paint paramPaint, int paramInt1, int paramInt2, int paramInt3) {
   Object localObject = new Path();
   float f1 = paramInt1 - paramInt3 * 2.0F;
   float f2 = paramInt2 - paramInt3 * 2.0F;
   float f3 = f1 / 10.0F;
   ((Path) localObject).moveTo(paramInt3, paramInt3);
   ((Path) localObject).lineTo(paramInt3 + (f1 - f3) / 2.0F, paramInt3 + f2 / 2.0F);
   ((Path) localObject).lineTo(paramInt3, paramInt3 + f2);
   ((Path) localObject).lineTo(paramInt3, paramInt3);
   ((Path) localObject).moveTo(paramInt3 + (f1 - f3) / 2.0F, paramInt3);
   ((Path) localObject).lineTo(paramInt3 + f1 - f3, paramInt3 + f2 / 2.0F);
   ((Path) localObject).lineTo(paramInt3 + (f1 - f3) / 2.0F, paramInt3 + f2);
   ((Path) localObject).lineTo(paramInt3 + (f1 - f3) / 2.0F, paramInt3);
   paramCanvas.drawPath((Path) localObject, paramPaint);
   localObject = new Paint();
   ((Paint) localObject).setDither(true);
   ((Paint) localObject).setColor(paramPaint.getColor());
   ((Paint) localObject).setStyle(Paint.Style.STROKE);
   ((Paint) localObject).setStrokeWidth(f3);
   paramCanvas.drawLine(
       paramInt3 + f1 - f3 / 2.0F,
       paramInt3,
       paramInt3 + f1 - f3 / 2.0F,
       f2 + paramInt3,
       (Paint) localObject);
 }
コード例 #23
0
 private void setPaintColor_inDIV(Paint p, int color) {
   p.setDither(true);
   p.setColor(color);
   p.setStyle(Paint.Style.STROKE);
   p.setStrokeCap(Paint.Cap.ROUND);
   p.setStrokeJoin(Paint.Join.ROUND);
   p.setStrokeWidth(4);
 }
コード例 #24
0
 public TrackingPatternView(Context context, AttributeSet attributeset) {
   super(context, attributeset);
   mTexture = BitmapFactory.decodeResource(getResources(), 0x108056f);
   mTextureWidth = mTexture.getWidth();
   mTextureHeight = mTexture.getHeight();
   mPaint = new Paint();
   mPaint.setDither(false);
 }
コード例 #25
0
ファイル: EventMod.java プロジェクト: ladams14640/MiWatch-1
  private void initPaint() {
    mPaint = new Paint();
    mPaint.setColor(getResources().getColor(android.R.color.white));
    mPaint.setTextSize(textSize);
    mPaint.setTypeface(Typeface.DEFAULT);
    mPaint.setAntiAlias(true);
    mPaint.setDither(false);
    mPaint.setTextAlign(Paint.Align.LEFT);

    mPaintInfo = new Paint();
    mPaintInfo.setColor(getResources().getColor(R.color.digital_time_blue));
    mPaintInfo.setTextSize(textSize);
    mPaintInfo.setTypeface(Typeface.DEFAULT);
    mPaintInfo.setAntiAlias(true);
    mPaintInfo.setDither(false);
    mPaintInfo.setTextAlign(Paint.Align.LEFT);
  }
コード例 #26
0
ファイル: ImageRotate.java プロジェクト: gityouzi/Camera
 @Override
 protected void drawShape(Canvas canvas, Bitmap image) {
   gPaint.setAntiAlias(true);
   gPaint.setFilterBitmap(true);
   gPaint.setDither(true);
   gPaint.setARGB(255, 255, 255, 255);
   drawTransformedCropped(canvas, image, gPaint);
 }
コード例 #27
0
  private void drawCirc(Canvas canvas) {
    Paint paint = new Paint();
    paint.setColor(Color.RED);
    paint.setAntiAlias(true);
    paint.setDither(true);

    canvas.drawCircle(iconRect.right, (iconRect.bottom / 3), 10, paint);
  }
コード例 #28
0
  /**
   * 获取裁剪后的圆形图片
   *
   * @param radius 半径
   */
  public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;

    // 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图片
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    int squareWidth = 0, squareHeight = 0;
    int x = 0, y = 0;
    Bitmap squareBitmap;
    if (bmpHeight > bmpWidth) { // 高大于宽
      squareWidth = squareHeight = bmpWidth;
      x = 0;
      y = (bmpHeight - bmpWidth) / 2;
      // 截取正方形图片
      squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
    } else if (bmpHeight < bmpWidth) { // 宽大于高
      squareWidth = squareHeight = bmpHeight;
      x = (bmpWidth - bmpHeight) / 2;
      y = 0;
      squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
    } else {
      squareBitmap = bmp;
    }

    if (squareBitmap.getWidth() != diameter || squareBitmap.getHeight() != diameter) {
      scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);

    } else {
      scaledSrcBmp = squareBitmap;
    }
    Bitmap output =
        Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

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

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(
        scaledSrcBmp.getWidth() / 2,
        scaledSrcBmp.getHeight() / 2,
        scaledSrcBmp.getWidth() / 2,
        paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
    // bitmap回收(recycle导致在布局文件XML看不到效果)
    // bmp.recycle();
    // squareBitmap.recycle();
    // scaledSrcBmp.recycle();
    bmp = null;
    squareBitmap = null;
    scaledSrcBmp = null;
    return output;
  }
コード例 #29
0
 public void setPaintColor(int color) {
   currentPaint = new Paint();
   currentPaint.setDither(true);
   currentPaint.setColor(color);
   currentPaint.setStyle(Paint.Style.STROKE);
   currentPaint.setStrokeJoin(Paint.Join.ROUND);
   currentPaint.setStrokeCap(Paint.Cap.ROUND);
   currentPaint.setStrokeWidth(20);
 }
コード例 #30
0
 // init paint
 private void Init_Paint(int color, int width) {
   mPaint.setAntiAlias(true);
   mPaint.setDither(true);
   mPaint.setColor(color);
   mPaint.setStyle(Paint.Style.STROKE);
   mPaint.setStrokeJoin(Paint.Join.ROUND);
   mPaint.setStrokeCap(Paint.Cap.ROUND);
   mPaint.setStrokeWidth(width);
 }