package com.android.launcher;
import android.graphics.drawable.Drawable;
import android.graphics.PixelFormat;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
class FastBitmapDrawable extends Drawable {
private Bitmap mBitmap;
FastBitmapDrawable(Bitmap b) {
mBitmap = b;
}
@Override
public void draw(Canvas canvas) {
canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null);
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
@Override
public int getIntrinsicWidth() {
return mBitmap.getWidth();
}
@Override
public int getIntrinsicHeight() {
return mBitmap.getHeight();
}
@Override
public int getMinimumWidth() {
return mBitmap.getWidth();
}
@Override
public int getMinimumHeight() {
return mBitmap.getHeight();
}
public Bitmap getBitmap() {
return mBitmap;
}
}
package com.android.launcher; import android.graphics.drawable.Drawable; import android.graphics.PixelFormat; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.ColorFilter; class FastBitmapDrawable
Share
It’s not really fair to compare a FastBitmapDrawable to a Bitmap. Traditional Bitmaps are just a type of
Objectin Java. FastBitmapDrawables however, are a custom class written to extend the functionality of theDrawableclass, not theBitmapclass.A FastBitmapDrawable contains a traditional Bitmap, and makes a few assumptions that make it convenient to use in certain situations. This is the crucial line:
This FastBitmapDrawable assumes that the bitmap will be placed at (0, 0) on the screen, and that no special Paint object will be used to draw it.
Really it’s just a convenience. You could get the same performance by manually setting the position to (0, 0) and the Paint to null in a normal
Drawable, but this class does that for you automatically.