BitmapDrawable getBitmap - 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 getBitmap method.

This code example shows how to use the following methods:getBitmap
    public void constructors_shouldSetBitmap() throws Exception { 
        Bitmap bitmap = Robolectric.newInstanceOf(Bitmap.class);
        BitmapDrawable drawable = new BitmapDrawable(bitmap);
        assertEquals(bitmap, drawable.getBitmap());
 
        drawable = new BitmapDrawable(resources, bitmap);
        assertEquals(bitmap, drawable.getBitmap());
    } 
 
    @Test 
    public void getBitmap_shouldReturnBitmapUsedToDraw() throws Exception { 
        BitmapDrawable drawable = (BitmapDrawable) resources.getDrawable(R.drawable.an_image);
        assertEquals("Bitmap for resource:org.robolectric:drawable/an_image", shadowOf(drawable.getBitmap()).getDescription());
    } 
 
    @Test 
    public void mutate_createsDeepCopy() throws Exception { 
        BitmapDrawable original = (BitmapDrawable) resources.getDrawable(R.drawable.an_image);
        Drawable mutated = original.mutate();
        assertNotSame(original, mutated);
7
CodeRank
This code example shows how to use the following methods:getBitmap, setTargetDensity
            painter.setIntrinsicWidth(width);
            painter.setIntrinsicHeight(height);
        } else if (icon instanceof BitmapDrawable) {
            // Ensure the bitmap has a density. 
            BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(mDisplayMetrics);
            } 
        } 
        int sourceWidth = icon.getIntrinsicWidth();
        int sourceHeight = icon.getIntrinsicHeight();
 
        if (sourceWidth > 0 && sourceHeight > 0) {
            // There are intrinsic sizes. 
            if (width < sourceWidth || height < sourceHeight) {
                // It's too big, scale it down. 
                final float ratio = (float) sourceWidth / sourceHeight;
                if (sourceWidth > sourceHeight) {
                    height = (int) (width / ratio);
7
CodeRank
This code example shows how to use the following methods:getBitmap
     
    @Override 
    public void drawBitmap(String name, float xc, float yc, float w, float h,
                           float angle) {
        final Drawable drawable = mCache != null ? mCache.getImage(mView, name)
                : name == null ? new BitmapDrawable(mView.getResources(), getHandleBitmap(3)) : null;
         
        if (drawable != null) {
            Matrix mat = new Matrix();
            int width = ImageCache.getWidth(drawable);
            int height = ImageCache.getHeight(drawable);
             
            mat.postTranslate(-0.5f * width, -0.5f * height);
            mat.postRotate(-angle * 180.f / 3.1415926f); // degree to radian
            mat.postScale(w / width, h / height);
            mat.postTranslate(xc, yc);
             
            try { 
                BitmapDrawable b = (BitmapDrawable)drawable;
                mCanvas.drawBitmap(b.getBitmap(), mat, null);

7
CodeRank
This code example shows how to use the following methods:getBitmap
     */ 
    @Implementation 
    public void draw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColorFilter(colorFilter);
        canvas.drawBitmap(realBitmapDrawable.getBitmap(), 0, 0, paint);
    } 
 
    @Implementation 
    public Drawable mutate() {
        BitmapDrawable real = newInstanceOf(BitmapDrawable.class);
        ShadowBitmapDrawable shadow = shadowOf(real);
        shadow.setBitmap(bitmap);
        shadow.colorFilter = this.colorFilter;
        shadow.drawableCreateFromStreamSource = drawableCreateFromStreamSource;
        return real;
    } 
 
    @Implementation 
    public void setColorFilter(android.graphics.ColorFilter colorFilter) {
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:getBitmap
    } 
 
    @Override 
    protected int sizeOf(String key, BitmapDrawable value) {
        if (value != null) {
            Bitmap b = value.getBitmap();
            if (b != null)
                return b.getRowBytes() * b.getHeight();
        } 
        return 0; 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getBitmap, setTargetDensity
This code example shows how to use the following methods:getBitmap, setTargetDensity
            painter.setIntrinsicWidth(width);
            painter.setIntrinsicHeight(height);
        } else if (icon instanceof BitmapDrawable) {
            // Ensure the bitmap has a density. 
            BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(mDisplayMetrics);
            } 
        } 
        int sourceWidth = icon.getIntrinsicWidth();
        int sourceHeight = icon.getIntrinsicHeight();
 
        if (sourceWidth > 0 && sourceWidth > 0) {
            // There are intrinsic sizes. 
            if (width < sourceWidth || height < sourceHeight) {
                // It's too big, scale it down. 
                final float ratio = (float) sourceWidth / sourceHeight;
                if (sourceWidth > sourceHeight) {
                    height = (int) (width / ratio);
7
CodeRank
This code example shows how to use the following methods:getBitmap
     */ 
    @Implementation 
    public void draw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColorFilter(colorFilter);
        canvas.drawBitmap(realBitmapDrawable.getBitmap(), 0, 0, paint);
    } 
 
    @Implementation 
    public void setColorFilter(android.graphics.ColorFilter colorFilter) {
        this.colorFilter = colorFilter;
    } 
 
    @Implementation 
    public android.graphics.Bitmap getBitmap() {
        return bitmap;
    } 
 
    /** 
     * Non-Android accessor that tells you the resource id that this {@code BitmapDrawable} was loaded from. This lets 
6
CodeRank
This code example shows how to use the following methods:getBitmap, setColorFilter, setFilterBitmap
	public ArcadeButtonView( Context context, ArcadeButton button )
	{ 
		this.button = button;
 
		Bitmap bitmap = BitmapFactory.decodeResource( context.getResources(), R.drawable.arcade_button );
		BitmapDrawable bitmapDrawable = new BitmapDrawable( context.getResources(), bitmap );
		bitmapDrawable.setFilterBitmap( true );
		bitmapDrawable.setColorFilter( new LightingColorFilter( this.button.getColour(), 1 ) );
 
		this.bitmap = bitmapDrawable.getBitmap();
		this.calcBounds();
	} 
 
} 
6
CodeRank

Related BitmapDrawable getBitmap Questions & Answers:

getBitmap Method Overview
Returns the bitmap used by this drawable to render.
See Code Examples for other Android BitmapDrawable Methods: