Search in sources :

Example 6 with BitmapShader

use of android.graphics.BitmapShader in project CircularImageView by Pkmmte.

the class RoundTransform method transform.

@Override
public Bitmap transform(final Bitmap source) {
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);
    if (source != output) {
        source.recycle();
    }
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader)

Example 7 with BitmapShader

use of android.graphics.BitmapShader in project HoloEverywhere by Prototik.

the class ProgressBar method tileify.

private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];
        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i), id == android.R.id.progress || id == android.R.id.secondaryProgress);
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);
        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }
        return newBg;
    } else if (drawable instanceof StateListDrawable) {
        StateListDrawable in = (StateListDrawable) drawable;
        StateListDrawable out = new StateListDrawable();
        int numStates = ReflectHelper.invoke(in, "getStateCount", int.class);
        for (int i = 0; i < numStates; i++) {
            out.addState(ReflectHelper.invoke(in, "getStateSet", int[].class, i), tileify(ReflectHelper.invoke(in, "getStateDrawable", Drawable.class, i), clip));
        }
        return out;
    } else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }
        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        return clip ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }
    return drawable;
}
Also used : Bitmap(android.graphics.Bitmap) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) BitmapShader(android.graphics.BitmapShader) SuppressLint(android.annotation.SuppressLint) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 8 with BitmapShader

use of android.graphics.BitmapShader in project Rajawali by Rajawali.

the class GitHubLogoView method onSizeChanged.

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mDrawingRect = new Rect(0, 0, w, h);
    final Bitmap mask = convertToAlphaMask(Bitmap.createScaledBitmap(mMask, w, h, false));
    mPaint.setShader(new BitmapShader(mask, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    mBackground = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    mBackgroundCanvas.setBitmap(mBackground);
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) BitmapShader(android.graphics.BitmapShader)

Example 9 with BitmapShader

use of android.graphics.BitmapShader in project ProgressWheel by Todd-Davies.

the class Main method randomBg.

private static void randomBg(ProgressWheel wheel) {
    Random random = new Random();
    int firstColour = random.nextInt();
    int secondColour = random.nextInt();
    int patternSize = (1 + random.nextInt(3)) * 8;
    int patternChange = (1 + random.nextInt(3)) * 8;
    int[] pixels = new int[patternSize];
    for (int i = 0; i < patternSize; i++) {
        pixels[i] = (i > patternChange) ? firstColour : secondColour;
    }
    wheel.setRimShader(new BitmapShader(Bitmap.createBitmap(pixels, patternSize, 1, Bitmap.Config.ARGB_8888), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
}
Also used : Random(java.util.Random) BitmapShader(android.graphics.BitmapShader)

Example 10 with BitmapShader

use of android.graphics.BitmapShader in project Carbon by ZieIony.

the class CheckableDrawable method renderSVGs.

private void renderSVGs() {
    Rect bounds = getBounds();
    if (bounds.width() <= 0 && bounds.height() <= 0)
        return;
    try {
        {
            SVG svg = SVG.getFromResource(context, checkedRes);
            checkedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(checkedBitmap);
            svg.setDocumentWidth(checkedBitmap.getWidth());
            svg.setDocumentHeight(checkedBitmap.getHeight());
            svg.renderToCanvas(canvas);
            checkedShader = new BitmapShader(checkedBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
            Matrix matrix = new Matrix();
            matrix.postTranslate(bounds.left, bounds.top);
            checkedShader.setLocalMatrix(matrix);
        }
        {
            SVG svg2 = SVG.getFromResource(context, uncheckedRes);
            uncheckedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(uncheckedBitmap);
            svg2.setDocumentWidth(uncheckedBitmap.getWidth());
            svg2.setDocumentHeight(uncheckedBitmap.getHeight());
            svg2.renderToCanvas(canvas);
        }
        {
            SVG svg3 = SVG.getFromResource(context, filledRes);
            filledBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(filledBitmap);
            svg3.setDocumentWidth(filledBitmap.getWidth());
            svg3.setDocumentHeight(filledBitmap.getHeight());
            svg3.renderToCanvas(canvas);
        }
        maskBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
        maskCanvas = new Canvas(maskBitmap);
        radius = (float) (Math.sqrt(2) * bounds.width() / 2);
    } catch (SVGParseException e) {
        Log.e(CheckableDrawable.class.getSimpleName(), "There was an error parsing SVG");
    } catch (NullPointerException e) {
    // TODO: what is this catch for?
    }
}
Also used : Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) SVG(com.caverock.androidsvg.SVG) SVGParseException(com.caverock.androidsvg.SVGParseException) Canvas(android.graphics.Canvas) BitmapShader(android.graphics.BitmapShader)

Aggregations

BitmapShader (android.graphics.BitmapShader)135 Bitmap (android.graphics.Bitmap)86 Paint (android.graphics.Paint)69 Canvas (android.graphics.Canvas)60 Matrix (android.graphics.Matrix)20 BitmapDrawable (android.graphics.drawable.BitmapDrawable)15 RectF (android.graphics.RectF)14 ShapeDrawable (android.graphics.drawable.ShapeDrawable)14 AnimationDrawable (android.graphics.drawable.AnimationDrawable)13 ClipDrawable (android.graphics.drawable.ClipDrawable)13 Drawable (android.graphics.drawable.Drawable)13 LayerDrawable (android.graphics.drawable.LayerDrawable)13 Rect (android.graphics.Rect)9 Shader (android.graphics.Shader)8 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)6 StateListDrawable (android.graphics.drawable.StateListDrawable)4 Point (android.graphics.Point)3 SuppressLint (android.annotation.SuppressLint)2 ColorMatrix (android.graphics.ColorMatrix)2 TypedArray (android.content.res.TypedArray)1