Java 类android.graphics.Paint 实例源码

项目:GitHub    文件:PacmanIndicator.java   
private void drawPacman(Canvas canvas,Paint paint){
    float x=getWidth()/2;
    float y=getHeight()/2;

    canvas.save();

    canvas.translate(x, y);
    canvas.rotate(degrees1);
    paint.setAlpha(255);
    RectF rectF1=new RectF(-x/1.7f,-y/1.7f,x/1.7f,y/1.7f);
    canvas.drawArc(rectF1, 0, 270, true, paint);

    canvas.restore();

    canvas.save();
    canvas.translate(x, y);
    canvas.rotate(degrees2);
    paint.setAlpha(255);
    RectF rectF2=new RectF(-x/1.7f,-y/1.7f,x/1.7f,y/1.7f);
    canvas.drawArc(rectF2,90,270,true,paint);
    canvas.restore();
}
项目:HutHelper    文件:CirclePie.java   
private void drawCenterText(Canvas canvas) {
    canvas.save();
    paint3.setStyle(Paint.Style.FILL);
    paint3.setColor(Color.WHITE);
    paint3.setFakeBoldText(true);
    paint3.setTextSize(topTextSize);
    String content1 = (maxNum-currNum) + "/" + maxNum;
    canvas.drawText(content1, -paint3.measureText(content1) / 2, 0, paint3);
    paint3.setTextSize(bottomTextSize);
    String content = "未得学分/总学分";
    paint3.setFakeBoldText(false);
    Rect r = new Rect();
    paint3.getTextBounds(content, 0, content.length(), r);
    canvas.drawText(content, -r.width() / 2, r.height() + 20, paint3);
    canvas.restore();
}
项目:FriendBook    文件:SimulationPageAnim.java   
public SimulationPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组
    float array[] = { 1, 0, 0, 0, 0,
            0, 1, 0, 0, 0,
            0, 0,1, 0, 0,
            0, 0, 0, 1, 0 };
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouchX = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouchY = 0.01f;
}
项目:My-Android-Base-Code    文件:SubUtils.java   
public static Bitmap scaleBitmap(Bitmap bitmap, int newWidth, int newHeight) {
    Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);

    float scaleX = newWidth / (float) bitmap.getWidth();
    float scaleY = newHeight / (float) bitmap.getHeight();
    float pivotX = 0;
    float pivotY = 0;

    Matrix scaleMatrix = new Matrix();
    scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);

    Canvas canvas = new Canvas(scaledBitmap);
    canvas.setMatrix(scaleMatrix);
    canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG));

    return scaledBitmap;
}
项目:LJFramework    文件:ImageUtils.java   
/**
 * 添加图片水印
 *
 * @param src 源图片
 * @param watermark 图片水印
 * @param x 起始坐标x
 * @param y 起始坐标y
 * @param alpha 透明度
 * @param recycle 是否回收
 * @return 带有图片水印的图片
 */
public static Bitmap addImageWatermark(Bitmap src, Bitmap watermark, int x, int y, int alpha, boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    Bitmap ret = src.copy(src.getConfig(), true);
    if (!isEmptyBitmap(watermark)) {
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        Canvas canvas = new Canvas(ret);
        paint.setAlpha(alpha);
        canvas.drawBitmap(watermark, x, y, paint);
    }
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return ret;
}
项目:appinventor-extensions    文件:Canvas.java   
/**
 * Specifies the alignment of the canvas's text: center, normal
 * (starting at the specified point in DrawText() or DrawAngle()),
 * or opposite (ending at the specified point in DrawText() or
 * DrawAngle()).
 *
 * @param alignment  one of {@link Component#ALIGNMENT_NORMAL},
 *                   {@link Component#ALIGNMENT_CENTER} or
 *                   {@link Component#ALIGNMENT_OPPOSITE}
 */
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXTALIGNMENT,
                  defaultValue = DEFAULT_TEXTALIGNMENT + "")
@SimpleProperty(userVisible = true)
public void TextAlignment(int alignment) {
  this.textAlignment = alignment;
  switch (alignment) {
    case Component.ALIGNMENT_NORMAL:
      paint.setTextAlign(Paint.Align.LEFT);
      break;
    case Component.ALIGNMENT_CENTER:
      paint.setTextAlign(Paint.Align.CENTER);
      break;
    case Component.ALIGNMENT_OPPOSITE:
      paint.setTextAlign(Paint.Align.RIGHT);
      break;
  }
}
项目:shareNote    文件:GlideCircleTransform.java   
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;

    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
项目:FlexibleRichTextView    文件:JavaFontRenderingBox.java   
public JavaFontRenderingBox(String str, int type, float size, Typeface f,
            boolean kerning) {
        this.str = str;
        this.size = size;
        //计算出文字需要的宽高
//      Paint pFont=AjLatexMath.getPaint();
//      pFont.setTextSize(AjLatexMath.getTextSize());
        Paint pFont =new Paint();
        Rect rect = new Rect();
        pFont.getTextBounds(str, 0, str.length(), rect);
         this.height = (float) (-rect.top * size / 2);
         this.depth = (float) ((rect.height() * size / 2) - this.height);
         this.width = (float) ((rect.width() + rect.right + 0.4f) * size /
         4);
        System.out.println(" width="+width+" height="+height+" text="+str);
    }
项目:AndroidPDF    文件:PDFView.java   
/** Construct the initial view */
public PDFView(Context context, AttributeSet set) {
    super(context, set);
    miniMapRequired = false;
    cacheManager = new CacheManager();
    animationManager = new AnimationManager(this);
    dragPinchManager = new DragPinchManager(this);

    paint = new Paint();
    debugPaint = new Paint();
    debugPaint.setStyle(Style.STROKE);
    paintMinimapBack = new Paint();
    paintMinimapBack.setStyle(Style.FILL);
    paintMinimapBack.setColor(Color.BLACK);
    paintMinimapBack.setAlpha(50);
    paintMinimapFront = new Paint();
    paintMinimapFront.setStyle(Style.FILL);
    paintMinimapFront.setColor(Color.BLACK);
    paintMinimapFront.setAlpha(50);

    // A surface view does not call
    // onDraw() as a default but we need it.
    setWillNotDraw(false);
}
项目:memento-app    文件:ImageHelper.java   
public static Bitmap highlightSelectedFaceThumbnail(Bitmap originalBitmap) {
    Bitmap bitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.parseColor("#3399FF"));
    int stokeWidth = Math.max(originalBitmap.getWidth(), originalBitmap.getHeight()) / 10;
    if (stokeWidth == 0) {
        stokeWidth = 1;
    }
    bitmap.getWidth();
    paint.setStrokeWidth(stokeWidth);
    canvas.drawRect(
            0,
            0,
            bitmap.getWidth(),
            bitmap.getHeight(),
            paint);

    return bitmap;
}
项目:AndroidOCRFforID    文件:AspectRatioTextView.java   
@SuppressWarnings("deprecation")
private void init(@NonNull TypedArray a) {
    setGravity(Gravity.CENTER_HORIZONTAL);

    mAspectRatioTitle = a.getString(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_title);
    mAspectRatioX = a.getFloat(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_x, CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
    mAspectRatioY = a.getFloat(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_y, CropImageView.SOURCE_IMAGE_ASPECT_RATIO);

    if (mAspectRatioX == CropImageView.SOURCE_IMAGE_ASPECT_RATIO || mAspectRatioY == CropImageView.SOURCE_IMAGE_ASPECT_RATIO) {
        mAspectRatio = CropImageView.SOURCE_IMAGE_ASPECT_RATIO;
    } else {
        mAspectRatio = mAspectRatioX / mAspectRatioY;
    }

    mDotSize = getContext().getResources().getDimensionPixelSize(R.dimen.ucrop_size_dot_scale_text_view);
    mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaint.setStyle(Paint.Style.FILL);

    setTitle();

    int activeColor = getResources().getColor(R.color.ucrop_color_widget_active);
    applyActiveColor(activeColor);

    a.recycle();
}
项目:DMAudioStreamer    文件:PlayPauseView.java   
public PlayPauseView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setWillNotDraw(false);

    TypedValue colorTheme = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorAccent, colorTheme, true);

    mBackgroundColor = Color.parseColor("#000000");//colorTheme.data;
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.FILL);
    mDrawable = new PlayPauseDrawable(context);
    mDrawable.setCallback(this);

    mPauseBackgroundColor = Color.parseColor("#000000");//colorTheme.data;
    mPlayBackgroundColor = Color.parseColor("#000000");//colorTheme.data;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PlayPause);
    isDrawCircle = a.getBoolean(R.styleable.PlayPause_isCircleDraw, isDrawCircle);
}
项目:BBSSDK-for-Android    文件:ImageUtils.java   
/**
 * 添加图片水印
 *
 * @param src       源图片
 * @param watermark 图片水印
 * @param x         起始坐标x
 * @param y         起始坐标y
 * @param alpha     透明度
 * @param recycle   是否回收
 * @return 带有图片水印的图片
 */
public static Bitmap addImageWatermark(final Bitmap src, final Bitmap watermark, final int x
        , final int y, final int alpha, final boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    Bitmap ret = src.copy(src.getConfig(), true);
    if (!isEmptyBitmap(watermark)) {
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        Canvas canvas = new Canvas(ret);
        paint.setAlpha(alpha);
        canvas.drawBitmap(watermark, x, y, paint);
    }
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return ret;
}
项目:NeiHanDuanZiTV    文件:FastBlur.java   
public static Bitmap blurBitmap(Bitmap bkg, int width, int height) {
    long startMs = System.currentTimeMillis();
    float radius = 15;//越大模糊效果越大
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, width, height);
    Bitmap overlay = Bitmap.createBitmap((int) (width / scaleFactor)
            , (int) (height / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
    return overlay;
}
项目:HeadlineNews    文件:ImageUtils.java   
/**
 * 转为圆形图片
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return 圆形图片
 */
public static Bitmap toRound(final Bitmap src, final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int radius = Math.min(width, height) >> 1;
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    Paint paint = new Paint();
    Canvas canvas = new Canvas(ret);
    Rect rect = new Rect(0, 0, width, height);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(width >> 1, height >> 1, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, rect, rect, paint);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:Paathshala    文件:MainActivity.java   
public static Bitmap getCircularBitmapFrom(Bitmap bitmap) {
    if (bitmap == null || bitmap.isRecycled()) {
        return null;
    }
    float radius = bitmap.getWidth() > bitmap.getHeight() ? ((float) bitmap
            .getHeight()) / 2f : ((float) bitmap.getWidth()) / 2f;
    Bitmap canvasBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP,
            Shader.TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(shader);

    Canvas canvas = new Canvas(canvasBitmap);

    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
            radius, paint);

    return canvasBitmap;
}
项目:FlexibleRichTextView    文件:GeoGebraLogoBox.java   
public void draw(Canvas g2, float x, float y) {
    g2.save();
    Paint st = AjLatexMath.getPaint();
    int c = st.getColor();
    Style s = st.getStyle();
    float w = st.getStrokeWidth();

    g2.translate(x + 0.25f * height / 2.15f, y - 1.75f / 2.15f * height);
    st.setColor(gray);
    st.setStrokeWidth(3.79999995f);
    g2.scale(0.05f * height / 2.15f, 0.05f * height / 2.15f);
    g2.rotate((float) Math.toDegrees((-26 * Math.PI / 180)), 20.5f, 17.5f);
    g2.drawArc(new RectF(0f, 0f, 43f, 32f), 0f, 360f, false, st);
    g2.rotate((float) Math.toDegrees((26 * Math.PI / 180)), 20.5f, 17.5f);
    st.setStyle(Style.STROKE);
    drawCircle(st, g2, 16f, -5f);
    drawCircle(st, g2, -1f, 7f);
    drawCircle(st, g2, 5f, 28f);
    drawCircle(st, g2, 27f, 24f);
    drawCircle(st, g2, 36f, 3f);

    st.setColor(c);
    st.setStyle(s);
    st.setStrokeWidth(w);
    g2.restore();
}
项目:ReadMark    文件:ELetter.java   
@Override
protected void initConfig(int x, int y) {
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(mStrokeWidth);
    mPaint.setAntiAlias(true);
    mPaint.setColor(Config.WHITE);
    mPaint.setStrokeCap(Paint.Cap.SQUARE);

    mRectF = new RectF(x - MAX_RADIUS_CIRCLE
            , y - MAX_RADIUS_CIRCLE
            , x + MAX_RADIUS_CIRCLE
            , y + MAX_RADIUS_CIRCLE);
    mFirstPoint = new Point(x - MAX_RADIUS_CIRCLE, y);
    mSecondPoint = new Point(mFirstPoint);
}
项目:materialExpansionPanel    文件:ExpandableUtils.java   
static Bitmap getRoundedSquareBitmap(Drawable drawable, int color) {
    float radius = 250.0f;
    Bitmap bitmap = drawableToBitmap(drawable);

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
项目:cardinalsSample    文件:RoundProgressBar.java   
public RoundProgressBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    paint = new Paint();

    TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundProgressBar);

    //获取自定义属性和默认值
    roundColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundColor, Color.GRAY);
    roundProgressColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundProgressColor, Color.BLUE);
    textColor = mTypedArray.getColor(R.styleable.RoundProgressBar_textColor, Color.BLUE);
    textSize = mTypedArray.getDimension(R.styleable.RoundProgressBar_textSize, 14);
    roundWidth = mTypedArray.getDimension(R.styleable.RoundProgressBar_roundWidth, 4);
    max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, 100);
    textIsDisplayable = mTypedArray.getBoolean(R.styleable.RoundProgressBar_textIsDisplayable, true);
    style = mTypedArray.getInt(R.styleable.RoundProgressBar_style, STROKE);

    mTypedArray.recycle();
}
项目:androidgithub    文件:QrCodeFinderView.java   
private void initAttrs(Context context, AttributeSet attrs) {
        mContext = context;
        mPaint = new Paint();
        int statusBarHeight = getStatusBarHeight(context);
//        if (mScreenWidth == 0 || mScreenHeight == 0) {
//            DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
//            mScreenWidth = displayMetrics.widthPixels;
//            mScreenHeight = displayMetrics.heightPixels;
////            mScreenHeight = displayMetrics.heightPixels - statusBarHeight;
//        }

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.QrCodeFinderView);
        mViewWidth = (int) typedArray.getDimension(R.styleable.QrCodeFinderView_innerWidth, 720f);
        mViewHeight = (int) typedArray.getDimension(R.styleable.QrCodeFinderView_innerHeight, 720f);
        mAngleThick = (int) typedArray.getDimension(R.styleable.QrCodeFinderView_innerAngleThick, 12f);
        mAngleLength = (int) typedArray.getDimension(R.styleable.QrCodeFinderView_innerAngleLength, 60f);
        mMaskColor = typedArray.getColor(R.styleable.QrCodeFinderView_maskColor, Color.parseColor("#70000000"));
        mFrameColor = typedArray.getColor(R.styleable.QrCodeFinderView_frameColor, Color.TRANSPARENT);
        mLaserColor = typedArray.getColor(R.styleable.QrCodeFinderView_laserColor, Color.parseColor("#37C222"));

    }
项目:IdealMedia    文件:MusicPlayerView.java   
/**
 * Create shader and set shader to mPaintCover
 */
private void createShader() {

    if (mWidth == 0)
        return;

    //if mBitmapCover is null then create default colored cover
    if (mBitmapCover == null) {
        mBitmapCover = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
        mBitmapCover.eraseColor(mCoverColor);
    }

    mCoverScale = ((float) mWidth) / (float) mBitmapCover.getWidth();

    mBitmapCover = Bitmap.createScaledBitmap(mBitmapCover,
            (int) (mBitmapCover.getWidth() * mCoverScale),
            (int) (mBitmapCover.getHeight() * mCoverScale),
            true);

    mShader = new BitmapShader(mBitmapCover, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mPaintCover = new Paint();
    mPaintCover.setAntiAlias(true);
    mPaintCover.setShader(mShader);

}
项目:terminal-seekbar    文件:TerminalSeekBar.java   
/**
 * getting the fields initialized ...
 */
private void initialize() {

    absLeft = getPaddingLeft() + mPaddingSize;
    absRight = getWidth() - getPaddingRight() - mPaddingSize;
    absTop = getPaddingTop() + mPaddingSize;
    absBottom = getHeight() - getPaddingBottom() - mPaddingSize;

    thumbRadius = thumbHeight / 2;
    mPaddingSize = (int) thumbRadius;
    barWidth = absRight - absLeft;

    mSeekBarRect = new Rect(absLeft, absTop, absRight, absTop + barHeight);

    mSeekBarGradient = new LinearGradient(0, 0, mSeekBarRect.width(), 0, mBarColor, mBarColor, Shader.TileMode.MIRROR);
    mBarRectPaint = new Paint();
    mBarRectPaint.setShader(mSeekBarGradient);
    mBarRectPaint.setAntiAlias(true);

    terminalRadius = barHeight / 2 + 5;

}
项目:tuxguitar    文件:TGPainterImpl.java   
public void closePath(){
    if(! this.pathEmpty ){
        if( (this.style & PATH_DRAW) != 0){
            this.paint.setStyle(Paint.Style.STROKE);
            this.paint.setColor(this.foreground.getHandle(this.alpha) );
            this.canvas.drawPath(this.path,this.paint);
        }
        if( (this.style & PATH_FILL) != 0){
            this.paint.setStyle(Paint.Style.FILL);
            this.paint.setColor(this.background.getHandle(this.alpha) );
            this.canvas.drawPath(this.path,this.paint);
        }
    }

    this.style = 0;
    this.path = null;
    this.pathEmpty = true;
    this.setAntialias(false);
}
项目:RoundButton    文件:CircularRevealAnimatedDrawable.java   
/**
 * @param view      The view that if being animated
 * @param fillColor The color of the background that will the revealed
 * @param bitmap    The animage that will be shown in the end of the animation.
 */
public CircularRevealAnimatedDrawable(View view, int fillColor, Bitmap bitmap) {
    mAnimatedView = view;
    isRunning = false;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(fillColor);

    mPaintImageReady = new Paint();
    mPaintImageReady.setAntiAlias(true);
    mPaintImageReady.setStyle(Paint.Style.FILL);
    mPaintImageReady.setColor(Color.TRANSPARENT);

    mReadyImage = bitmap;
    mImageReadyAlpha = 0;

    mRadius = 0;
}
项目:qmui    文件:QMUIAlignMiddleImageSpan.java   
@Override
    public void draw(Canvas canvas, CharSequence text, int start, int end,
                     float x, int top, int y, int bottom, Paint paint) {
        if (mVerticalAlignment == ALIGN_MIDDLE) {
            Drawable d = getDrawable();
            canvas.save();

//            // 注意如果这样实现会有问题:TextView 有 lineSpacing 时,这里 bottom 偏大,导致偏下
//            int transY = bottom - d.getBounds().bottom; // 底对齐
//            transY -= (paint.getFontMetricsInt().bottom - paint.getFontMetricsInt().top) / 2 - d.getBounds().bottom / 2; // 居中对齐
//            canvas.translate(x, transY);
//            d.draw(canvas);
//            canvas.restore();

            Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
            int fontTop = y + fontMetricsInt.top;
            int fontMetricsHeight = fontMetricsInt.bottom - fontMetricsInt.top;
            int iconHeight = d.getBounds().bottom - d.getBounds().top;
            int iconTop = fontTop + (fontMetricsHeight - iconHeight) / 2;
            canvas.translate(x, iconTop);
            d.draw(canvas);
            canvas.restore();
        } else {
            super.draw(canvas, text, start, end, x, top, y, bottom, paint);
        }
    }
项目:RNLearn_Project1    文件:ARTShapeShadowNode.java   
@Override
public void draw(Canvas canvas, Paint paint, float opacity) {
  opacity *= mOpacity;
  if (opacity > MIN_OPACITY_FOR_DRAW) {
    saveAndSetupCanvas(canvas);
    if (mPath == null) {
      throw new JSApplicationIllegalArgumentException(
          "Shapes should have a valid path (d) prop");
    }
    if (setupFillPaint(paint, opacity)) {
      canvas.drawPath(mPath, paint);
    }
    if (setupStrokePaint(paint, opacity)) {
      canvas.drawPath(mPath, paint);
    }
    restoreCanvas(canvas);
  }
  markUpdateSeen();
}
项目:LJFramework    文件:ImageUtils.java   
/**
 * 转为灰度图片
 *
 * @param src 源图片
 * @param recycle 是否回收
 * @return 灰度图
 */
public static Bitmap toGray(Bitmap src, boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    Bitmap grayBitmap = Bitmap.createBitmap(src.getWidth(), src
            .getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(grayBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixColorFilter);
    canvas.drawBitmap(src, 0, 0, paint);
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return grayBitmap;
}
项目:Zxing    文件:CaptureActivity.java   
/**
 * 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 rawResult The decoded results which contains the points to draw.
 */
private 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().equals(BarcodeFormat.UPC_A))
            || (rawResult.getBarcodeFormat().equals(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);
            }
        }
    }
}
项目:Discover    文件:BallTrianglePathIndicator.java   
@Override
public void draw(Canvas canvas, Paint paint) {
    paint.setStrokeWidth(3);
    paint.setStyle(Paint.Style.STROKE);
    for (int i = 0; i < 3; i++) {
        canvas.save();
        canvas.translate(translateX[i], translateY[i]);
        canvas.drawCircle(0, 0, getWidth() / 10, paint);
        canvas.restore();
    }
}
项目:GoogleMapsLayout-Android    文件:MarkerBitmapFactory.java   
public static Bitmap getMarkerWithHaloBitmap(Bitmap bitmap, int haloRadius, int haloColor) {
    if(2*haloRadius > bitmap.getWidth() || 2*haloRadius > bitmap.getHeight()){
        Paint paint = new Paint();
        Bitmap.Config bitmapConfig = Bitmap.Config.ARGB_8888;
        Bitmap newBitmap = Bitmap.createBitmap(2*haloRadius, 2*haloRadius, bitmapConfig);
        Canvas canvas = new Canvas(newBitmap);
        paint.setColor(haloColor);
        canvas.drawCircle(haloRadius,haloRadius,haloRadius,paint);
        canvas.drawBitmap(bitmap,haloRadius-bitmap.getWidth()/2,haloRadius-bitmap.getHeight()/2,null);
        return newBitmap;
    }
    return bitmap;
}
项目:AOSP-Kayboard-7.1.2    文件:MoreKeysKeyboard.java   
private static int getMaxKeyWidth(final Key parentKey, final int minKeyWidth,
        final float padding, final Paint paint) {
    int maxWidth = minKeyWidth;
    for (final MoreKeySpec spec : parentKey.getMoreKeys()) {
        final String label = spec.mLabel;
        // If the label is single letter, minKeyWidth is enough to hold the label.
        if (label != null && StringUtils.codePointCount(label) > 1) {
            maxWidth = Math.max(maxWidth,
                    (int)(TypefaceUtils.getStringWidth(label, paint) + padding));
        }
    }
    return maxWidth;
}
项目:SSTVEncoder2    文件:LabelPainter.java   
@Override
public void draw(Canvas canvas) {
    mPaint.setColor(mLabel.getForeColor());
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawPath(mPath, mPaint);

    mPaint.setColor(Color.WHITE);
    mPaint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(mPath, mPaint);
}
项目:FlexibleRichTextView    文件:GeoGebraLogoBox.java   
private static void drawCircle(Paint st, Canvas g2, float x, float y) {
    st.setColor(blue);
    g2.translate(x, y);
    g2.drawCircle(0, 0, 8, st);
    st.setColor(Color.BLACK);
    st.setStyle(Style.STROKE);
    g2.drawCircle(0, 0, 8, st);
    g2.translate(-x, -y);
}
项目:SmartRefreshLayout    文件:RippleView.java   
public RippleView(Context context) {
    super(context);
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setColor(0xffffffff);
    mPaint.setStyle(Paint.Style.FILL);
}
项目:ScannerView    文件:ScannerView.java   
private void init() {
    arrRadarObjects = new ArrayList<>();
    setDummyData();

    mPaintBack = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintRing = new Paint(Paint.ANTI_ALIAS_FLAG);
}
项目:Android-UtilCode    文件:ImageUtils.java   
/**
 * 添加图片水印
 *
 * @param src       源图片
 * @param watermark 图片水印
 * @param x         起始坐标x
 * @param y         起始坐标y
 * @param alpha     透明度
 * @param recycle   是否回收
 * @return 带有图片水印的图片
 */
public static Bitmap addImageWatermark(Bitmap src, Bitmap watermark, int x, int y, int alpha, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.copy(src.getConfig(), true);
    if (!isEmptyBitmap(watermark)) {
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        Canvas canvas = new Canvas(ret);
        paint.setAlpha(alpha);
        canvas.drawBitmap(watermark, x, y, paint);
    }
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:PeSanKita-android    文件:CanvasView.java   
/**
 * This method creates the instance of Paint.
 * In addition, this method sets styles for Paint.
 *
 * @return paint This is returned as the instance of Paint
 */
private Paint createPaint() {
  Paint paint = new Paint();

  paint.setAntiAlias(true);
  paint.setStyle(this.paintStyle);
  paint.setStrokeWidth(this.paintStrokeWidth);
  paint.setStrokeCap(this.lineCap);
  paint.setStrokeJoin(Paint.Join.MITER);  // fixed

  // for Text
  if (this.mode == Mode.TEXT) {
    paint.setTypeface(this.fontFamily);
    paint.setTextSize(this.fontSize);
    paint.setTextAlign(this.textAlign);
    paint.setStrokeWidth(0F);
  }

  if (this.mode == Mode.ERASER) {
    // Eraser
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    paint.setARGB(0, 0, 0, 0);

    // paint.setColor(this.baseColor);
    // paint.setShadowLayer(this.blur, 0F, 0F, this.baseColor);
  } else {
    // Otherwise
    paint.setColor(this.paintStrokeColor);
    paint.setShadowLayer(this.blur, 0F, 0F, this.paintStrokeColor);
    paint.setAlpha(this.opacity);
  }

  return paint;
}
项目:CXJPadProject    文件:PLViewfinderView.java   
public PLViewfinderView(Context context, int w, int h) {
    super(context);
    this.w = w;
    this.h = h;
    paint = new Paint();
    paintLine = new Paint();
    Resources resources = getResources();
    maskColor = resources.getColor(R.color.viewfinder_mask);
    resultColor = resources.getColor(R.color.result_view);
    frameColor = resources.getColor(R.color.viewfinder_frame);// 绿色
    laserColor = resources.getColor(R.color.viewfinder_laser);// 红色
    scannerAlpha = 0;
}
项目:BookReader-master    文件:EasyRVHolder.java   
@Override
public EasyRVHolder setTypeface(int viewId, Typeface typeface) {
    TextView view = getView(viewId);
    view.setTypeface(typeface);
    view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    return this;
}