Search in sources :

Example 61 with BitmapShader

use of android.graphics.BitmapShader in project weex-example by KalicyZhou.

the class ImageDrawable method createImageDrawable.

public static Drawable createImageDrawable(@Nullable Drawable original, @NonNull ImageView.ScaleType scaleType, @Nullable float[] borderRadius, int vWidth, int vHeight, boolean gif) {
    Bitmap bm;
    if (!gif && vWidth > 0 && vHeight > 0) {
        if (original instanceof BitmapDrawable && (bm = ((BitmapDrawable) original).getBitmap()) != null) {
            ImageDrawable imageDrawable;
            imageDrawable = new ImageDrawable();
            imageDrawable.bitmapWidth = bm.getWidth();
            imageDrawable.bitmapHeight = bm.getHeight();
            BitmapShader bitmapShader = new BitmapShader(bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
            updateShaderAndSize(scaleType, vWidth, vHeight, imageDrawable, bitmapShader);
            imageDrawable.getPaint().setShader(bitmapShader);
            return imageDrawable;
        } else if (original instanceof ImageDrawable) {
            ImageDrawable imageDrawable = (ImageDrawable) original;
            if (imageDrawable.getPaint() != null && imageDrawable.getPaint().getShader() instanceof BitmapShader) {
                BitmapShader bitmapShader = (BitmapShader) imageDrawable.getPaint().getShader();
                updateShaderAndSize(scaleType, vWidth, vHeight, imageDrawable, bitmapShader);
                return imageDrawable;
            }
        }
    }
    return original;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapShader(android.graphics.BitmapShader)

Example 62 with BitmapShader

use of android.graphics.BitmapShader in project android_frameworks_base by AOSPA.

the class TaskViewThumbnail method setThumbnail.

/** Sets the thumbnail to a given bitmap. */
void setThumbnail(Bitmap bm, ActivityManager.TaskThumbnailInfo thumbnailInfo) {
    if (bm != null) {
        bm.prepareToDraw();
        mBitmapShader = new BitmapShader(bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mDrawPaint.setShader(mBitmapShader);
        mThumbnailRect.set(0, 0, bm.getWidth(), bm.getHeight());
        mThumbnailInfo = thumbnailInfo;
        updateThumbnailScale();
    } else {
        mBitmapShader = null;
        mDrawPaint.setShader(null);
        mThumbnailRect.setEmpty();
        mThumbnailInfo = null;
    }
}
Also used : BitmapShader(android.graphics.BitmapShader)

Example 63 with BitmapShader

use of android.graphics.BitmapShader in project android_frameworks_base by DirtyUnicorns.

the class TaskViewThumbnail method setThumbnail.

/** Sets the thumbnail to a given bitmap. */
void setThumbnail(Bitmap bm, ActivityManager.TaskThumbnailInfo thumbnailInfo) {
    if (bm != null) {
        bm.prepareToDraw();
        float INITIAL_SCALE = 0.75f;
        int h = bm.getHeight();
        int w = bm.getWidth();
        Bitmap cropped = null;
        int mode = currentHandsMode();
        try {
            if (mode == 1) {
                cropped = Bitmap.createBitmap(bm, 0, (int) (h * (1 - INITIAL_SCALE)), (int) (w * INITIAL_SCALE), (int) (h * INITIAL_SCALE));
            } else if (mode == 2) {
                cropped = Bitmap.createBitmap(bm, (int) (w * (1 - INITIAL_SCALE)), (int) (h * (1 - INITIAL_SCALE)), (int) (w * INITIAL_SCALE), (int) (h * INITIAL_SCALE));
            }
        } catch (Exception e) {
            cropped = bm;
        }
        mBitmapShader = new BitmapShader(mode != 0 ? cropped : bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mDrawPaint.setShader(mBitmapShader);
        mThumbnailRect.set(0, 0, mode != 0 ? cropped.getWidth() : w, mode != 0 ? cropped.getHeight() : h);
        mThumbnailInfo = thumbnailInfo;
        updateThumbnailScale();
    } else {
        mBitmapShader = null;
        mDrawPaint.setShader(null);
        mThumbnailRect.setEmpty();
        mThumbnailInfo = null;
    }
}
Also used : Bitmap(android.graphics.Bitmap) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Example 64 with BitmapShader

use of android.graphics.BitmapShader in project httpclient by pixmob.

the class IcsProgressBar method tileify.

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
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 /* else if (drawable instanceof StateListDrawable) {
            StateListDrawable in = (StateListDrawable) drawable;
            StateListDrawable out = new StateListDrawable();
            int numStates = in.getStateCount();
            for (int i = 0; i < numStates; i++) {
                out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
            }
            return out;

        }*/
    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) 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) BitmapShader(android.graphics.BitmapShader) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 65 with BitmapShader

use of android.graphics.BitmapShader in project 9GAG by stormzhang.

the class TitanicTextView method createShader.

/**
 * Create the shader
 * draw the wave with current color for a background
 * repeat the bitmap horizontally, and clamp colors vertically
 */
private void createShader() {
    if (wave == null) {
        wave = getResources().getDrawable(R.drawable.wave);
    }
    int waveW = wave.getIntrinsicWidth();
    int waveH = wave.getIntrinsicHeight();
    Bitmap b = Bitmap.createBitmap(waveW, waveH, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.drawColor(getCurrentTextColor());
    wave.setBounds(0, 0, waveW, waveH);
    wave.draw(c);
    shader = new BitmapShader(b, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
    getPaint().setShader(shader);
    offsetY = (getHeight() - waveH) / 2;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapShader(android.graphics.BitmapShader)

Aggregations

BitmapShader (android.graphics.BitmapShader)137 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