搜索

首页  >  问答  >  正文

android - 自定义的drawable能够转换成bitmap吗

1.这是自定义的drawable,怎样转换成bitmap?

public class TextDrawable extends Drawable {

    private final String text;
    private final Paint paint;

    public TextDrawable(String text) {

        this.text = text;

        this.paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setTextSize(22f);
        paint.setAntiAlias(true);
        paint.setFakeBoldText(true);
        paint.setShadowLayer(6f, 0, 0, Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextAlign(Paint.Align.LEFT);
    }

    @Override
    public void draw(Canvas canvas) {
        canvas.drawText(text, 0, 0, paint);
    }

    @Override
    public void setAlpha(int alpha) {
        paint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
        paint.setColorFilter(cf);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}
伊谢尔伦伊谢尔伦2771 天前619

全部回复(2)我来回复

  • 迷茫

    迷茫2017-04-17 17:28:43

    雷雷

    http://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap

    回复
    0
  • 黄舟

    黄舟2017-04-17 17:28:43

    可以得,网上不是大把drawable转bitmap的么

    回复
    0
  • 取消回复