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

2023-11-06 22:51

本文主要是介绍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!");}@NonNullpublic static Bitmap createBitmap(@NonNull Picture source) {throw new RuntimeException("Stub!");}@NonNullpublic 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 */@DeprecatedARGB_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;

这篇关于android业务实现1:文本转点阵图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/359537

相关文章

C#实现将Excel表格转换为图片(JPG/ PNG)

《C#实现将Excel表格转换为图片(JPG/PNG)》Excel表格可能会因为不同设备或字体缺失等问题,导致格式错乱或数据显示异常,转换为图片后,能确保数据的排版等保持一致,下面我们看看如何使用C... 目录通过C# 转换Excel工作表到图片通过C# 转换指定单元格区域到图片知识扩展C# 将 Excel

Android Mainline基础简介

《AndroidMainline基础简介》AndroidMainline是通过模块化更新Android核心组件的框架,可能提高安全性,本文给大家介绍AndroidMainline基础简介,感兴趣的朋... 目录关键要点什么是 android Mainline?Android Mainline 的工作原理关键

基于Java实现回调监听工具类

《基于Java实现回调监听工具类》这篇文章主要为大家详细介绍了如何基于Java实现一个回调监听工具类,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录监听接口类 Listenable实际用法打印结果首先,会用到 函数式接口 Consumer, 通过这个可以解耦回调方法,下面先写一个

使用Java将DOCX文档解析为Markdown文档的代码实现

《使用Java将DOCX文档解析为Markdown文档的代码实现》在现代文档处理中,Markdown(MD)因其简洁的语法和良好的可读性,逐渐成为开发者、技术写作者和内容创作者的首选格式,然而,许多文... 目录引言1. 工具和库介绍2. 安装依赖库3. 使用Apache POI解析DOCX文档4. 将解析

Qt中QGroupBox控件的实现

《Qt中QGroupBox控件的实现》QGroupBox是Qt框架中一个非常有用的控件,它主要用于组织和管理一组相关的控件,本文主要介绍了Qt中QGroupBox控件的实现,具有一定的参考价值,感兴趣... 目录引言一、基本属性二、常用方法2.1 构造函数 2.2 设置标题2.3 设置复选框模式2.4 是否

C++使用printf语句实现进制转换的示例代码

《C++使用printf语句实现进制转换的示例代码》在C语言中,printf函数可以直接实现部分进制转换功能,通过格式说明符(formatspecifier)快速输出不同进制的数值,下面给大家分享C+... 目录一、printf 原生支持的进制转换1. 十进制、八进制、十六进制转换2. 显示进制前缀3. 指

springboot整合阿里云百炼DeepSeek实现sse流式打印的操作方法

《springboot整合阿里云百炼DeepSeek实现sse流式打印的操作方法》:本文主要介绍springboot整合阿里云百炼DeepSeek实现sse流式打印,本文给大家介绍的非常详细,对大... 目录1.开通阿里云百炼,获取到key2.新建SpringBoot项目3.工具类4.启动类5.测试类6.测

pytorch自动求梯度autograd的实现

《pytorch自动求梯度autograd的实现》autograd是一个自动微分引擎,它可以自动计算张量的梯度,本文主要介绍了pytorch自动求梯度autograd的实现,具有一定的参考价值,感兴趣... autograd是pytorch构建神经网络的核心。在 PyTorch 中,结合以下代码例子,当你

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

SpringBoot集成Milvus实现数据增删改查功能

《SpringBoot集成Milvus实现数据增删改查功能》milvus支持的语言比较多,支持python,Java,Go,node等开发语言,本文主要介绍如何使用Java语言,采用springboo... 目录1、Milvus基本概念2、添加maven依赖3、配置yml文件4、创建MilvusClient