BitmapDrawable draw - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for BitmapDrawable draw method.

This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setAlpha
            return; 
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.translate(mX, mY);
        canvas.scale(mScaleX, mScaleY);
        canvas.translate(-0.5f*getWidth(), -0.5f*getHeight());
        mDrawable.setAlpha((int) Math.round(mAlpha * 255f));
        mDrawable.draw(canvas);
        canvas.restore();
    } 
 
    /** 
     * Starts all animations added since the last call to this function.  Used to synchronize 
     * animations. 
     * 
     * @param listener an optional listener to add to the animations. Typically used to know when 
     * to invalidate the surface these are being drawn to. 
     */ 
    public void startAnimations(ValueAnimator.AnimatorUpdateListener listener) {
        for (int i = 0; i < mNeedToStart.size(); i++) {
            ObjectAnimator anim = mNeedToStart.get(i);

8
CodeRank
This code example shows how to use the following methods:draw, setAlpha
        if (placeholder != null) {
          placeholder.draw(canvas);
        } 
 
        int alpha = (int) (0xFF * normalized);
        image.setAlpha(alpha);
        image.draw(canvas);
        image.setAlpha(0xFF);
        invalidateSelf();
      } 
    } 
 
    if (debugging) {
      drawDebugIndicator(canvas);
    } 
  } 
 
  @Override public int getIntrinsicWidth() { 
    return image.getIntrinsicWidth();
  } 
8
CodeRank
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setAlpha
            return; 
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.translate(mX, mY);
        canvas.scale(mScaleX, mScaleY);
        canvas.translate(-0.5f*getWidth(), -0.5f*getHeight());
        mDrawable.setAlpha((int) Math.round(mAlpha * 255f));
        mDrawable.draw(canvas);
        canvas.restore();
    } 
 
    /** 
     * Starts all animations added since the last call to this function.  Used to synchronize 
     * animations. 
     * 
     * @param listener an optional listener to add to the animations. Typically used to know when 
     * to invalidate the surface these are being drawn to. 
     */ 
    public void startAnimations(ValueAnimator.AnimatorUpdateListener listener) {
        for (int i = 0; i < mNeedToStart.size(); i++) {
            ObjectAnimator anim = mNeedToStart.get(i);

7
CodeRank
This code example shows how to use the following methods:draw, getBitmap, setBounds
		switch(new Random().nextInt(3)) {
			case(0): circle(c, w, h, s, paint()); break;
			case(1): triangle(c, w, h, s, paint()); break;
			case(2): rectangle(c, w, h, s, paint()); break;
		} 
		BitmapDrawable bd = new BitmapDrawable(b);
		bd.setBounds(0, 0, w, h);
		bd.draw(c);
		return bd.getBitmap();
	} 
	public void circle(Canvas c, int w, int h, int s, Paint p) {
		c.drawCircle(w/2, h/2, s/2, p);
	} 
	public void triangle(Canvas c, int w, int h, int s, Paint p) {
		double r = 0.0174632929265499; // pi/180
		int x1 = w/2;
		s = (int)(s*0.57);
		int y1 = h/2 - (int)s;
		int x2 = (int)(w/2 + Math.cos(r*30) * s);
		int y2 = (int)(h/2 + Math.sin(r*30) * s);
7
CodeRank
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, getOpacity, setBounds
This code example shows how to use the following methods:draw
        this(drawable.mDrawable);
    } 
 
    @Override 
    public void draw(Canvas canvas) {
        mDrawable.draw(canvas);
    } 
 
    @Override 
    public int getOpacity() { 
        return mDrawable.getOpacity();
    } 
 
    @Override 
    public void setAlpha(int alpha) {
        mDrawable.setAlpha(alpha);
    } 
 
    @Override 
    public void setColorFilter(ColorFilter cf) {
6
CodeRank
This code example shows how to use the following methods:draw, setAlpha, setBounds
 
	@Override 
	public void draw(Canvas c) {
		switchCount--;
		if(switchCount==0){
			targetReticle = new BitmapDrawable(tR);//avoid new if inefficient
		} 
		if(target!=null){
			calcAlpha(); 
			targetReticle.setAlpha(alpha);
			//Log.e("fail", "target"); 
			targetReticle.setBounds(target.getX(), target.getY(), target.getX()+target.getWidth(), target.getY()+target.getHeight());
			targetReticle.draw(c);
		} 
	} 
	private void calcAlpha() { 
		alpha+=alphaChange;
		if(alpha>255){
			alphaChange=-alphaChange;
			alpha = 255;
6
CodeRank
This code example shows how to use the following methods:draw, getBounds, setBounds
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setColorFilter, setBounds
    public static Bitmap recolorBitmap(BitmapDrawable drawable, int color) {
        if (drawable == null) {
            return null; 
        } 
 
        Bitmap outBitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(outBitmap);
        drawable.setBounds(0, 0, outBitmap.getWidth(), outBitmap.getHeight());
        drawable.setColorFilter(color,
                PorterDuff.Mode.SRC_IN);
        drawable.draw(canvas);
        drawable.setColorFilter(null);
        drawable.setCallback(null); // free up any references
        return outBitmap;
    } 
 
    public static Intent getDefaultClockIntent(Context context) {
        PackageManager pm = context.getPackageManager();
        for (String packageName : CLOCK_PACKAGES) {
6
CodeRank
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setBounds

Related BitmapDrawable draw Questions & Answers:

draw Method Overview
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).
See Code Examples for other Android BitmapDrawable Methods: