Search in sources :

Example 71 with Canvas

use of android.graphics.Canvas in project ShowcaseView by amlcurran.

the class StandardShowcaseDrawer method drawShowcase.

@Override
public void drawShowcase(Bitmap buffer, float x, float y, float scaleMultiplier) {
    Canvas bufferCanvas = new Canvas(buffer);
    bufferCanvas.drawCircle(x, y, showcaseRadius, eraserPaint);
    int halfW = getShowcaseWidth() / 2;
    int halfH = getShowcaseHeight() / 2;
    int left = (int) (x - halfW);
    int top = (int) (y - halfH);
    showcaseDrawable.setBounds(left, top, left + getShowcaseWidth(), top + getShowcaseHeight());
    showcaseDrawable.draw(bufferCanvas);
}
Also used : Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 72 with Canvas

use of android.graphics.Canvas in project iosched by google.

the class BezelImageView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    if (mBounds == null) {
        return;
    }
    int width = mBounds.width();
    int height = mBounds.height();
    if (width == 0 || height == 0) {
        return;
    }
    if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
        // Need to redraw the cache.
        if (width == mCachedWidth && height == mCachedHeight) {
            // Have a correct-sized bitmap cache already allocated. Just erase it.
            mCacheBitmap.eraseColor(0);
        } else {
            // Allocate a new bitmap with the correct dimensions.
            mCacheBitmap.recycle();
            //noinspection AndroidLintDrawAllocation
            mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            mCachedWidth = width;
            mCachedHeight = height;
        }
        Canvas cacheCanvas = new Canvas(mCacheBitmap);
        if (mMaskDrawable != null) {
            int sc = cacheCanvas.save();
            mMaskDrawable.draw(cacheCanvas);
            mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else if (mDesaturateOnPress && isPressed()) {
            int sc = cacheCanvas.save();
            cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
            mMaskedPaint.setColorFilter(mDesaturateColorFilter);
            cacheCanvas.saveLayer(mBoundsF, mMaskedPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
            super.onDraw(cacheCanvas);
            cacheCanvas.restoreToCount(sc);
        } else {
            super.onDraw(cacheCanvas);
        }
        if (mBorderDrawable != null) {
            mBorderDrawable.draw(cacheCanvas);
        }
    }
    // Draw from cache.
    canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}
Also used : Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 73 with Canvas

use of android.graphics.Canvas in project iosched by google.

the class UIUtils method vectorToBitmap.

public static Bitmap vectorToBitmap(@NonNull Context context, @DrawableRes int drawableResId) {
    VectorDrawableCompat vector = VectorDrawableCompat.create(context.getResources(), drawableResId, context.getTheme());
    final Bitmap bitmap = Bitmap.createBitmap(vector.getIntrinsicWidth(), vector.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);
    vector.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vector.draw(canvas);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat)

Example 74 with Canvas

use of android.graphics.Canvas in project android-maps-utils by googlemaps.

the class IconGenerator method makeIcon.

/**
     * Creates an icon with the current content and style.
     * <p/>
     * This method is useful if a custom view has previously been set, or if text content is not
     * applicable.
     */
public Bitmap makeIcon() {
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mContainer.measure(measureSpec, measureSpec);
    int measuredWidth = mContainer.getMeasuredWidth();
    int measuredHeight = mContainer.getMeasuredHeight();
    mContainer.layout(0, 0, measuredWidth, measuredHeight);
    if (mRotation == 1 || mRotation == 3) {
        measuredHeight = mContainer.getMeasuredWidth();
        measuredWidth = mContainer.getMeasuredHeight();
    }
    Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
    r.eraseColor(Color.TRANSPARENT);
    Canvas canvas = new Canvas(r);
    if (mRotation == 0) {
    // do nothing
    } else if (mRotation == 1) {
        canvas.translate(measuredWidth, 0);
        canvas.rotate(90);
    } else if (mRotation == 2) {
        canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
    } else {
        canvas.translate(0, measuredHeight);
        canvas.rotate(270);
    }
    mContainer.draw(canvas);
    return r;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Example 75 with Canvas

use of android.graphics.Canvas in project gdk-compass-sample by googleglass.

the class CompassRenderer method repaint.

/**
     * Repaints the compass.
     */
private synchronized void repaint() {
    Canvas canvas = null;
    try {
        canvas = mHolder.lockCanvas();
    } catch (RuntimeException e) {
        Log.d(TAG, "lockCanvas failed", e);
    }
    if (canvas != null) {
        canvas.drawColor(Color.BLACK);
        mLayout.draw(canvas);
        try {
            mHolder.unlockCanvasAndPost(canvas);
        } catch (RuntimeException e) {
            Log.d(TAG, "unlockCanvasAndPost failed", e);
        }
    }
}
Also used : Canvas(android.graphics.Canvas)

Aggregations

Canvas (android.graphics.Canvas)1237 Bitmap (android.graphics.Bitmap)890 Paint (android.graphics.Paint)609 Rect (android.graphics.Rect)257 BitmapDrawable (android.graphics.drawable.BitmapDrawable)192 RectF (android.graphics.RectF)136 PorterDuffXfermode (android.graphics.PorterDuffXfermode)103 Matrix (android.graphics.Matrix)80 Point (android.graphics.Point)76 Drawable (android.graphics.drawable.Drawable)68 BitmapShader (android.graphics.BitmapShader)60 Test (org.junit.Test)46 IOException (java.io.IOException)43 FileOutputStream (java.io.FileOutputStream)40 View (android.view.View)39 Path (android.graphics.Path)38 File (java.io.File)37 SuppressLint (android.annotation.SuppressLint)36 ColorMatrix (android.graphics.ColorMatrix)36 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)33