Java Code Examples for android.graphics.Paint.DITHER_FLAG

The following are Jave code examples for showing how to use DITHER_FLAG of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: kinemic-example-android   File: DrawingView.java   View Source Code Vote up 6 votes
public DrawingView(Context context) {
    super(context);
    mContext=context;
    mPath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(Color.GREEN);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(12);
    circlePaint = new Paint();
    circlePath = new Path();
    circlePaint.setAntiAlias(true);
    circlePaint.setColor(Color.BLUE);
    circlePaint.setStyle(Paint.Style.STROKE);
    circlePaint.setStrokeJoin(Paint.Join.MITER);
    circlePaint.setStrokeWidth(4f);
}
 
Example 2
Project: GitHub   File: FlikerProgressBar.java   View Source Code Vote up 6 votes
private void init() {
    bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    bgPaint.setStyle(Paint.Style.STROKE);
    bgPaint.setStrokeWidth(borderWidth);

    pgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    pgPaint.setStyle(Paint.Style.FILL);

    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(textSize);

    textRect = new Rect();
    bgRectf = new RectF(borderWidth, borderWidth, getMeasuredWidth() - borderWidth, getMeasuredHeight() - borderWidth);

    if(isStop){
        progressColor = stopColor;
    } else{
        progressColor = loadingColor;
    }

    flikerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.flicker);
    flickerLeft = -flikerBitmap.getWidth();

    initPgBimap();
}
 
Example 3
Project: GitHub   File: BitmapAnimationBackend.java   View Source Code Vote up 6 votes
public BitmapAnimationBackend(
    PlatformBitmapFactory platformBitmapFactory,
    BitmapFrameCache bitmapFrameCache,
    AnimationInformation animationInformation,
    BitmapFrameRenderer bitmapFrameRenderer,
    @Nullable BitmapFramePreparationStrategy bitmapFramePreparationStrategy,
    @Nullable BitmapFramePreparer bitmapFramePreparer) {
  mPlatformBitmapFactory = platformBitmapFactory;
  mBitmapFrameCache = bitmapFrameCache;
  mAnimationInformation = animationInformation;
  mBitmapFrameRenderer = bitmapFrameRenderer;
  mBitmapFramePreparationStrategy = bitmapFramePreparationStrategy;
  mBitmapFramePreparer = bitmapFramePreparer;

  mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
  updateBitmapDimensions();
}
 
Example 4
Project: Depth   File: CustomShadow.java   View Source Code Vote up 6 votes
public CustomShadow(
        Resources resources, int backgroundColor, float radius,
        float shadowSize, float maxShadowSize
) {
    mShadowStartColor = resources.getColor(R.color.cardview_shadow_start_color);
    mShadowEndColor = resources.getColor(R.color.cardview_shadow_end_color);
    mInsetShadow = resources.getDimensionPixelSize(R.dimen.cardview_compat_inset_shadow);
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(backgroundColor);
    mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mCornerShadowPaint.setStyle(Paint.Style.FILL);
    mCornerRadius = (int) (radius + .5f);
    mCardBounds = new RectF();
    mEdgeShadowPaint = new Paint(mCornerShadowPaint);
    mEdgeShadowPaint.setAntiAlias(false);
    setShadowSize(shadowSize, maxShadowSize);

    CustomShadow.sRoundRectHelper = new CustomShadow.RoundRectHelper() {
        @Override
        public void drawRoundRect(Canvas canvas, RectF bounds, float cornerRadius,
                                  Paint paint) {
            canvas.drawRoundRect(bounds, cornerRadius, cornerRadius, paint);
        }
    };
}
 
Example 5
Project: Aequorea   File: CircleTransformation.java   View Source Code Vote up 6 votes
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.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint
            .ANTI_ALIAS_FLAG);
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader
            .TileMode.CLAMP));
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
Example 6
Project: cwac-crossport   File: ShadowDrawableWrapper.java   View Source Code Vote up 6 votes
public ShadowDrawableWrapper(Context context, Drawable content, float radius,
          float shadowSize, float maxShadowSize) {
  super(content);

  mShadowStartColor = ContextCompat.getColor(context, R.color.design_fab_shadow_start_color);
  mShadowMiddleColor = ContextCompat.getColor(context, R.color.design_fab_shadow_mid_color);
  mShadowEndColor = ContextCompat.getColor(context, R.color.design_fab_shadow_end_color);

  mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
  mCornerShadowPaint.setStyle(Paint.Style.FILL);
  mCornerRadius = Math.round(radius);
  mContentBounds = new RectF();
  mEdgeShadowPaint = new Paint(mCornerShadowPaint);
  mEdgeShadowPaint.setAntiAlias(false);
  setShadowSize(shadowSize, maxShadowSize);
}
 
Example 7
Project: Hitalk   File: RoundRectDrawableWithShadow.java   View Source Code Vote up 6 votes
public RoundRectDrawableWithShadow(int backgroundColor, float radius,
                                   float shadowSize, float maxShadowSize) {
    if(DEBUG) Log.d(getClass().getSimpleName(), "RoundRectDrawableWithShadow("+radius+","+shadowSize+","+maxShadowSize+")");

    mInsetShadow = ViewUtils.dpToPx(SHADOW_INSET_DP);
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(backgroundColor);
    mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mCornerShadowPaint.setStyle(Paint.Style.FILL);
    mCornerRadius = (int) (radius + .5f);
    mCardBounds = new RectF();
    mEdgeShadowPaint = new Paint(mCornerShadowPaint);
    mEdgeShadowPaint.setAntiAlias(false);
    if(DEBUG) {
        mBoundsPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        mBoundsPaint.setColor(Color.BLACK);
        mBoundsPaint.setStyle(Paint.Style.STROKE);
        mBoundsPaint.setStrokeWidth(1);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(1);
        mCornerShadowPaint.setStrokeWidth(1);
    }
    setShadow(TOP|LEFT|RIGHT|BOTTOM);
    setShadowSize(shadowSize, maxShadowSize);
}
 
Example 8
Project: medialibrary   File: BitmapUtils.java   View Source Code Vote up 6 votes
public static Bitmap resizeAndCropCenter(Bitmap bitmap, int size, boolean recycle) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    if (w == size && h == size) return bitmap;

    // scale the image so that the shorter side equals to the target;
    // the longer side will be center-cropped.
    float scale = (float) size / Math.min(w,  h);

    Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap));
    int width = Math.round(scale * bitmap.getWidth());
    int height = Math.round(scale * bitmap.getHeight());
    Canvas canvas = new Canvas(target);
    canvas.translate((size - width) / 2f, (size - height) / 2f);
    canvas.scale(scale, scale);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle) bitmap.recycle();
    return target;
}
 
Example 9
Project: pius1   File: RoundRectDrawableWithShadow.java   View Source Code Vote up 5 votes
RoundRectDrawableWithShadow(Resources resources, int backgroundColor, float radius,
        float shadowSize, float maxShadowSize) {
    mShadowStartColor = resources.getColor(R.color.cardview_shadow_start_color);
    mShadowEndColor = resources.getColor(R.color.cardview_shadow_end_color);
    mInsetShadow = resources.getDimensionPixelSize(R.dimen.cardview_compat_inset_shadow);
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(backgroundColor);
    mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mCornerShadowPaint.setStyle(Paint.Style.FILL);
    mCornerRadius = (int) (radius + .5f);
    mCardBounds = new RectF();
    mEdgeShadowPaint = new Paint(mCornerShadowPaint);
    mEdgeShadowPaint.setAntiAlias(false);
    setShadowSize(shadowSize, maxShadowSize);
}
 
Example 10
Project: Sega   File: SimpleRatingBar.java   View Source Code Vote up 5 votes
/**
 * Inits paint objects and default values.
 */
private void initView() {
    starPath = new Path();
    cornerPathEffect = new CornerPathEffect(starCornerRadius);

    paintStarOutline = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    paintStarOutline.setStyle(Paint.Style.FILL_AND_STROKE);
    paintStarOutline.setAntiAlias(true);
    paintStarOutline.setDither(true);
    paintStarOutline.setStrokeJoin(Paint.Join.ROUND);
    paintStarOutline.setStrokeCap(Paint.Cap.ROUND);
    paintStarOutline.setColor(Color.BLACK);
    paintStarOutline.setPathEffect(cornerPathEffect);

    paintStarBorder = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    paintStarBorder.setStyle(Paint.Style.STROKE);
    paintStarBorder.setStrokeJoin(Paint.Join.ROUND);
    paintStarBorder.setStrokeCap(Paint.Cap.ROUND);
    paintStarBorder.setStrokeWidth(starBorderWidth);
    paintStarBorder.setPathEffect(cornerPathEffect);

    paintStarBackground = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    paintStarBackground.setStyle(Paint.Style.FILL_AND_STROKE);
    paintStarBackground.setAntiAlias(true);
    paintStarBackground.setDither(true);
    paintStarBackground.setStrokeJoin(Paint.Join.ROUND);
    paintStarBackground.setStrokeCap(Paint.Cap.ROUND);

    paintStarFill = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    paintStarFill.setStyle(Paint.Style.FILL_AND_STROKE);
    paintStarFill.setAntiAlias(true);
    paintStarFill.setDither(true);
    paintStarFill.setStrokeJoin(Paint.Join.ROUND);
    paintStarFill.setStrokeCap(Paint.Cap.ROUND);

    defaultStarSize = applyDimension(COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());
}
 
Example 11
Project: CXJPadProject   File: PaintView.java   View Source Code Vote up 5 votes
/***
 * 初始化
 */
private void init() {
    //关闭硬件加速
    //否则橡皮擦模式下,设置的 PorterDuff.Mode.CLEAR ,实时绘制的轨迹是黑色
    setBackgroundColor(Color.WHITE);//设置白色背景
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    //画笔
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setStrokeWidth(4f);
    mPaint.setAntiAlias(true);
    mPaint.setColor(Color.BLACK);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);//使画笔更加圆润
    mPaint.setStrokeCap(Paint.Cap.ROUND);//同上
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);
    //保存签名的画布
    post(new Runnable() {//拿到控件的宽和高
        @Override
        public void run() {
            //获取PaintView的宽和高
            //由于橡皮擦使用的是 Color.TRANSPARENT ,不能使用RGB-565
            mBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_4444);
            mCanvas = new Canvas(mBitmap);
            //抗锯齿
            mCanvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
            //背景色
            mCanvas.drawColor(Color.WHITE);
        }
    });

    undoList = new LinkedList<>();
    redoList = new LinkedList<>();
}
 
Example 12
Project: airgram   File: DrawingView.java   View Source Code Vote up 5 votes
private void init() {
  mPath = new Path();
  mBitmapPaint = new Paint(Paint.DITHER_FLAG);
  mPaint = new Paint();
  mPaint.setAntiAlias(true);
  mPaint.setDither(true);
  mPaint.setColor(Color.WHITE);
  mPaint.setStyle(Paint.Style.STROKE);
  mPaint.setStrokeJoin(Paint.Join.ROUND);
  mPaint.setStrokeCap(Paint.Cap.ROUND);
  mPaint.setStrokeWidth(mPenSize);
  mDrawMode = true;
  mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
}
 
Example 13
Project: airgram   File: PhotoCropView.java   View Source Code Vote up 5 votes
private Bitmap createBitmap(int x, int y, int w, int h) {
    Bitmap newBimap = delegate.getBitmap();
    if (newBimap != null) {
        bitmapToEdit = newBimap;
    }

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);

    Matrix matrix = new Matrix();
    matrix.setTranslate(-bitmapToEdit.getWidth() / 2, -bitmapToEdit.getHeight() / 2);
    matrix.postRotate(orientation);
    if (orientation % 360 == 90 || orientation % 360 == 270) {
        matrix.postTranslate(bitmapToEdit.getHeight() / 2 - x, bitmapToEdit.getWidth() / 2 - y);
    } else {
        matrix.postTranslate(bitmapToEdit.getWidth() / 2 - x, bitmapToEdit.getHeight() / 2 - y);
    }
    canvas.drawBitmap(bitmapToEdit, matrix, paint);
    try {
        canvas.setBitmap(null);
    } catch (Exception e) {
        //don't promt, this will crash on 2.x
    }

    return bitmap;
}
 
Example 14
Project: susi_android_v1   File: ChatMessageDrawable.java   View Source Code Vote up 5 votes
public ChatMessageDrawable(int backgroundColor, float radius) {
    mRadius = radius;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(backgroundColor);
    mBoundsF = new RectF();
    mBoundsI = new Rect();
}
 
Example 15
Project: labtablet   File: FingerPaintActivity.java   View Source Code Vote up 5 votes
public MyView(Context c) {
    super(c);
    context = c;
    mPath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);

}
 
Example 16
Project: android-palette   File: PaletteView.java   View Source Code Vote up 5 votes
private void init() {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setFilterBitmap(true);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mDrawSize = 20;
    mEraserSize = 40;
    mPaint.setStrokeWidth(mDrawSize);
    mPaint.setColor(0XFF000000);

    mClearMode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
}
 
Example 17
Project: Mire   File: CircleTransformHelper.java   View Source Code Vote up 5 votes
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.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG);
       paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
       
	float r = size / 2f;
       canvas.drawCircle(r, r, r, paint);
      
	return result;
   }
 
Example 18
Project: medialibrary   File: BitmapUtils.java   View Source Code Vote up 5 votes
public static Bitmap resizeBitmapByScale(
        Bitmap bitmap, float scale, boolean recycle) {
    int width = Math.round(bitmap.getWidth() * scale);
    int height = Math.round(bitmap.getHeight() * scale);
    if (width == bitmap.getWidth()
            && height == bitmap.getHeight()) return bitmap;
    Bitmap target = Bitmap.createBitmap(width, height, getConfig(bitmap));
    Canvas canvas = new Canvas(target);
    canvas.scale(scale, scale);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle) bitmap.recycle();
    return target;
}
 
Example 19
Project: HappyBubble   File: BubbleLayout.java   View Source Code Vote up 5 votes
public BubbleLayout(Context context, AttributeSet attrs, int defStyleAttr)
{
    super(context, attrs, defStyleAttr);
    setLayerType(LAYER_TYPE_SOFTWARE, null);
    setWillNotDraw(false);
    initAttr(context.obtainStyledAttributes(attrs, R.styleable.BubbleLayout, defStyleAttr, 0));
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setStyle(Paint.Style.FILL);
    mPath = new Path();
    initPadding();
}
 
Example 20
Project: Ec2m   File: WheelPicker_New.java   View Source Code Vote up 4 votes
public WheelPicker_New(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WheelPicker);
    int idData = a.getResourceId(R.styleable.WheelPicker_wheel_data, 0);
    mData = Arrays.asList(getResources()
            .getStringArray(idData == 0 ? R.array.WheelArrayDefault : idData));
    mItemTextSize = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_item_text_size,
            getResources().getDimensionPixelSize(R.dimen.WheelItemTextSize));
    mVisibleItemCount = a.getInt(R.styleable.WheelPicker_wheel_visible_item_count, 7);
    mSelectedItemPosition = a.getInt(R.styleable.WheelPicker_wheel_selected_item_position, 0);
    hasSameWidth = a.getBoolean(R.styleable.WheelPicker_wheel_same_width, false);
    mTextMaxWidthPosition =
            a.getInt(R.styleable.WheelPicker_wheel_maximum_width_text_position, -1);
    mMaxWidthText = a.getString(R.styleable.WheelPicker_wheel_maximum_width_text);
    mSelectedItemTextColor = a.getColor
            (R.styleable.WheelPicker_wheel_selected_item_text_color, -1);
    mItemTextColor = a.getColor(R.styleable.WheelPicker_wheel_item_text_color, 0xFF888888);
    mItemSpace = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_item_space,
            getResources().getDimensionPixelSize(R.dimen.WheelItemSpace));
    isCyclic = a.getBoolean(R.styleable.WheelPicker_wheel_cyclic, false);
    hasIndicator = a.getBoolean(R.styleable.WheelPicker_wheel_indicator, false);
    mIndicatorColor = a.getColor(R.styleable.WheelPicker_wheel_indicator_color, 0xFFEE3333);
    mIndicatorSize = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_indicator_size,
            getResources().getDimensionPixelSize(R.dimen.WheelIndicatorSize));
    hasCurtain = a.getBoolean(R.styleable.WheelPicker_wheel_curtain, false);
    mCurtainColor = a.getColor(R.styleable.WheelPicker_wheel_curtain_color, 0x88FFFFFF);
    hasAtmospheric = a.getBoolean(R.styleable.WheelPicker_wheel_atmospheric, false);
    isCurved = a.getBoolean(R.styleable.WheelPicker_wheel_curved, false);
    mItemAlign = a.getInt(R.styleable.WheelPicker_wheel_item_align, ALIGN_CENTER);
    a.recycle();

    // 可见数据项改变后更新与之相关的参数
    // Update relevant parameters when the count of visible item changed
    updateVisibleItemCount();

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.LINEAR_TEXT_FLAG);
    mPaint.setTextSize(mItemTextSize);

    // 更新文本对齐方式
    // Update alignment of text
    updateItemTextAlign();

    // 计算文本尺寸
    // Correct sizes of text
    computeTextSize();

    mScroller = new Scroller(getContext());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
        ViewConfiguration conf = ViewConfiguration.get(getContext());
        mMinimumVelocity = conf.getScaledMinimumFlingVelocity();
        mMaximumVelocity = conf.getScaledMaximumFlingVelocity();
        mTouchSlop = conf.getScaledTouchSlop();
    }
    mRectDrawn = new Rect();

    mRectIndicatorHead = new Rect();
    mRectIndicatorFoot = new Rect();

    mRectCurrentItem = new Rect();

    mCamera = new Camera();

    mMatrixRotate = new Matrix();
    mMatrixDepth = new Matrix();
}