android业务实现1:文本转点阵图

1、新建bitmap的方式很多

public static Bitmap createBitmap(@NonNull Bitmap src) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@NonNull Bitmap source, int x, int y, int width, int height) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@NonNull Bitmap source, int x, int y, int width, int height, @Nullable Matrix m, boolean filter) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(int width, int height, @NonNull Bitmap.Config config) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@Nullable DisplayMetrics display, int width, int height, @NonNull Bitmap.Config config) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(int width, int height, @NonNull Bitmap.Config config, boolean hasAlpha) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(int width, int height, @NonNull Bitmap.Config config, boolean hasAlpha, @NonNull ColorSpace colorSpace) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@Nullable DisplayMetrics display, int width, int height, @NonNull Bitmap.Config config, boolean hasAlpha) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@Nullable DisplayMetrics display, int width, int height, @NonNull Bitmap.Config config, boolean hasAlpha, @NonNull ColorSpace colorSpace) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@NonNull int[] colors, int offset, int stride, int width, int height, @NonNull Bitmap.Config config) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@NonNull DisplayMetrics display, @NonNull int[] colors, int offset, int stride, int width, int height, @NonNull Bitmap.Config config) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@NonNull int[] colors, int width, int height, Bitmap.Config config) {
        throw new RuntimeException("Stub!");
    }

    public static Bitmap createBitmap(@Nullable DisplayMetrics display, @NonNull int[] colors, int width, int height, @NonNull Bitmap.Config config) {
        throw new RuntimeException("Stub!");
    }

    @NonNull
    public static Bitmap createBitmap(@NonNull Picture source) {
        throw new RuntimeException("Stub!");
    }

    @NonNull
    public static Bitmap createBitmap(@NonNull Picture source, int width, int height, @NonNull Bitmap.Config config) {
        throw new RuntimeException("Stub!");
    }

这里选择第4种

 

public static Bitmap createBitmap(int width, int height, @NonNull Bitmap.Config config) {
    throw new RuntimeException("Stub!");
}
public static enum Config {
        ALPHA_8,
        RGB_565,
        /** @deprecated */
        @Deprecated
        ARGB_4444,
        ARGB_8888,
        RGBA_F16,
        HARDWARE;

        private Config() {
        }
    }


Bitmap bitmap= Bitmap.createBitmap(256,256, Bitmap.Config.ARGB_8888);

2、新建画布,设置字体

//画布
Canvas canvas=new Canvas(bitmap);
//背景色
canvas.drawColor(Color.WHITE);
//文本刷设置 
TextPaint textPaint = new TextPaint();
textPaint.setTextSize(16);
textPaint.setColor(Color.BLACK);
//写字板
/*
StaticLayout(CharSequence source, TextPaint paint, int width, Alignment align, float spacingmult, float spacingadd, boolean includepad)
source字符串来源,
paint文本刷,
width宽度,
align对齐:ALIGN_NORMAL, ALIGN_OPPOSITE,ALIGN_CENTER;
spacingmult行间距倍数
spacingadd增加行间距
includepad
*/
StaticLayout layout = new StaticLayout("https://blog.csdn.net/weixin_51380973",textPaint,256, Layout.Alignment.ALIGN_NORMAL,1.0F,0.0F,true);

 

3、在画布上绘制文本

canvas.translate(0,0);
layout.draw(canvas);
return bitmap;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值