Android 创建Bitmap

private Bitmap fromText(String text) {
        int dpSize = 12;//dp

        float pixel =TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dpSize, this.getResources().getDisplayMetrics());

        Paint paint = new Paint();
        paint.setTextSize(pixel);
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setAlpha(77);
        paint.setColor(Color.WHITE);

        Paint.FontMetricsInt fm = paint.getFontMetricsInt();

        int width = (int) paint.measureText(text);
        int height = fm.descent - fm.ascent;

        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawText(text, 0, fm.leading - fm.ascent, paint);
        canvas.save();

        return bitmap;
    }

Android 创建Bitmap

上一篇:JZ40 数组中只出现一次的两个数字


下一篇:Python 装饰器之 Property: Setter 和 Getter