├── .idea
└── vcs.xml
├── README.md
└── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── fmx
│ └── list
│ └── string2bitmap
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── assets
│ ├── fonts
│ │ └── songti.TTF
│ └── res
│ │ └── print.bmp
├── java
│ └── com
│ │ └── fmx
│ │ └── list
│ │ └── string2bitmap
│ │ ├── BitmapUtil.java
│ │ ├── MainActivity.java
│ │ └── StringBitmapParameter.java
└── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── test
└── java
└── com
└── fmx
└── list
└── string2bitmap
└── ExampleUnitTest.java
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # String2Bitmap
2 | 将文字生成图片的Utils
3 |
4 | bitmapToByteArrayForPrinter方法
5 |
6 | 该方法比较容易理解:
7 |
8 | 1.方法参数是待打印的文字的List集合,其中存放的就是一行行待打印的文字
9 | 2.读入参数后,先配置生成图片的宽度[为8的倍数],然后把每一行文字读入计,并计算这一行是否可以完全显示,如果不能一行显示需要多少行
10 | 3.设置文字的大小高度并计算一行文字的高度
11 | 4.生成空的位图
12 | 5.开始遍历List集合,绘制每一行
13 | 6.返回生成的图片
14 |
15 | 对于图片的合并,这个比文字生成图片更简单一点:
16 |
17 | 1.取出两张位图,把最宽的设置为宽度,高度之和设置为生成图片的高度
18 |
19 | int width = Math.max(first.getWidth(), second.getWidth());
20 | int height = first.getHeight() + second.getHeight();
21 |
22 | 2.这里比较麻烦的就是 logo的位置必须居中显示,所以我们需要把logo绘制的起点改变一下
23 |
24 | int startWidth = (width - first.getWidth()) / 2;
25 |
26 | 3.绘制即可
27 |
28 | Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
29 | Canvas canvas = new Canvas(result);
30 | canvas.drawBitmap(first, startWidth, 0, null);
31 | canvas.drawBitmap(second, 0, first.getHeight(), null);
32 |
33 | 原本List集合是文字,在List集合泛型的时候,不能在单纯的传入一个字段了,而是携带信息的参数
34 |
35 | /**
36 | * @param text 等待打印的字段
37 | * @param isRightOrLeft 可空,默认右边
38 | * @param isSmallOrLarge 可空,默认小字
39 | */
40 | public StringBitmapParameter(String text, int isRightOrLeft, int isSmallOrLarge) {
41 | this.text = text;
42 | this.isRightOrLeft = isRightOrLeft;
43 | this.isSmallOrLarge = isSmallOrLarge;
44 | }
45 | 在把文字构建图片的时候,由于是List存储的既是一行,所以我们这样做可以把每一行设置成左便开始打印还是右边,文字设置为大还是小,但是不能把文字的字体样式修改了
46 | for (StringBitmapParameter mParameter : mBreakString) {
47 | String str = mParameter.getText();
48 |
49 | if (mParameter.getIsSmallOrLarge() == IS_SMALL) {
50 | paint.setTextSize(SMALL_TEXT);
51 | } else if (mParameter.getIsSmallOrLarge() == IS_LARGE) {
52 | paint.setTextSize(LARGE_TEXT);
53 | }
54 |
55 | if (mParameter.getIsRightOrLeft() == IS_RIGHT) {
56 | x = WIDTH - paint.measureText(str);
57 | } else if (mParameter.getIsRightOrLeft() == IS_LEFT) {
58 | x = START_LEFT;
59 | } else if (mParameter.getIsRightOrLeft() == IS_CENTER) {
60 | x = (WIDTH - paint.measureText(str)) / 2.0f;
61 | }
62 |
63 | if (str.isEmpty() | str.contains("\n") | mParameter.getIsSmallOrLarge() == IS_LARGE) {
64 | canvas.drawText(str, x, y + FontHeight / 2, paint);
65 | y = y + FontHeight;
66 | } else {
67 | canvas.drawText(str, x, y, paint);
68 | }
69 | y = y + FontHeight;
70 | }
71 |
72 | 这里展示的即是关键位置
73 | 在图片的压缩这一部分,之前是ARGB_8888的,现在修改为了RGB_565,基本占内存小了一半,前者一个像素32位,后则16位,还有个模式是ALPHA_8仅仅有8位,但是这个模式下,打印出来的是纯黑的玩意,他只有透明度,没有颜色,所以不行,打印的时候也是把它变成黑白的打印的,而且这应该是压缩的极致了
74 | 现在就是合并图片生成的太慢,我觉得是我这里导致的:
75 |
76 | for (int i = 0; i < result.getWidth(); i++) {
77 | for (int j = 0; j < result.getHeight(); j++) {
78 | result.setPixel(i, j, Color.WHITE);
79 | }
80 | }
81 |
82 | 这个循环是为了把没个像素点都变成白的,然后再绘图,因为不这样做的话,图片打印出来,周边会有黑色条文,就是因为没有配色,他是透明的,所以打出来就是黑的导致的
83 | 所以如果把这个O(n^2)改变的话,就应该能加快生成图片的速度
84 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 | defaultConfig {
7 | applicationId "com.fmx.list.string2bitmap"
8 | minSdkVersion 19
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.0.0'
28 | testCompile 'junit:junit:4.12'
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\user\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/fmx/list/string2bitmap/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.fmx.list.string2bitmap;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.fmx.list.string2bitmap", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/songti.TTF:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dpuntu/String2Bitmap/24ee0568481fb8f3d3ac485c0cc738023240d1f8/app/src/main/assets/fonts/songti.TTF
--------------------------------------------------------------------------------
/app/src/main/assets/res/print.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dpuntu/String2Bitmap/24ee0568481fb8f3d3ac485c0cc738023240d1f8/app/src/main/assets/res/print.bmp
--------------------------------------------------------------------------------
/app/src/main/java/com/fmx/list/string2bitmap/BitmapUtil.java:
--------------------------------------------------------------------------------
1 | package com.fmx.list.string2bitmap;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.Typeface;
9 |
10 |
11 | import java.util.ArrayList;
12 |
13 | /**
14 | * Created by Dpuntu on 2017/3/8.
15 | */
16 | public class BitmapUtil {
17 | private final static int WIDTH = 384;
18 | private final static float SMALL_TEXT = 23;
19 | private final static float LARGE_TEXT = 35;
20 | private final static int START_RIGHT = WIDTH;
21 | private final static int START_LEFT = 0;
22 | private final static int START_CENTER = WIDTH / 2;
23 |
24 | /**
25 | * 特殊需求:
26 | */
27 | public final static int IS_LARGE = 10;
28 | public final static int IS_SMALL = 11;
29 | public final static int IS_RIGHT = 100;
30 | public final static int IS_LEFT = 101;
31 | public final static int IS_CENTER = 102;
32 |
33 |
34 | private static float x = START_LEFT, y;
35 |
36 | /**
37 | * 生成图片
38 | */
39 | public static Bitmap StringListtoBitmap(Context context, ArrayList AllString) {
40 | if (AllString.size() <= 0) return Bitmap.createBitmap(WIDTH, WIDTH / 4, Bitmap.Config.RGB_565);
41 | ArrayList mBreakString = new ArrayList<>();
42 |
43 | Paint paint = new Paint();
44 | paint.setAntiAlias(false);
45 | paint.setTextSize(SMALL_TEXT);
46 |
47 | Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/songti.TTF");// 仿宋打不出汉字
48 | Typeface font = Typeface.create(typeface, Typeface.NORMAL);
49 | paint.setTypeface(font);
50 |
51 | for (StringBitmapParameter mParameter : AllString) {
52 | int ALineLength = paint.breakText(mParameter.getText(), true, WIDTH, null);//检测一行多少字
53 | int lenght = mParameter.getText().length();
54 | if (ALineLength < lenght) {
55 |
56 | int num = lenght / ALineLength;
57 | String ALineString = new String();
58 | String RemainString = new String();
59 |
60 | for (int j = 0; j < num; j++) {
61 | ALineString = mParameter.getText().substring(j * ALineLength, (j + 1) * ALineLength);
62 | mBreakString.add(new StringBitmapParameter(ALineString, mParameter.getIsRightOrLeft(), mParameter.getIsSmallOrLarge()));
63 | }
64 |
65 | RemainString = mParameter.getText().substring(num * ALineLength, mParameter.getText().length());
66 | mBreakString.add(new StringBitmapParameter(RemainString, mParameter.getIsRightOrLeft(), mParameter.getIsSmallOrLarge()));
67 | } else {
68 | mBreakString.add(mParameter);
69 | }
70 | }
71 |
72 |
73 | Paint.FontMetrics fontMetrics = paint.getFontMetrics();
74 | int FontHeight = (int) Math.abs(fontMetrics.leading) + (int) Math.abs(fontMetrics.ascent) + (int) Math.abs(fontMetrics.descent);
75 | y = (int) Math.abs(fontMetrics.leading) + (int) Math.abs(fontMetrics.ascent);
76 |
77 | int bNum = 0;
78 | for (StringBitmapParameter mParameter : mBreakString) {
79 | String bStr = mParameter.getText();
80 | if (bStr.isEmpty() | bStr.contains("\n") | mParameter.getIsSmallOrLarge() == IS_LARGE)
81 | bNum++;
82 | }
83 | Bitmap bitmap = Bitmap.createBitmap(WIDTH, FontHeight * (mBreakString.size() + bNum), Bitmap.Config.RGB_565);
84 |
85 | for (int i = 0; i < bitmap.getWidth(); i++) {
86 | for (int j = 0; j < bitmap.getHeight(); j++) {
87 | bitmap.setPixel(i, j, Color.WHITE);
88 | }
89 | }
90 |
91 | Canvas canvas = new Canvas(bitmap);
92 |
93 | for (StringBitmapParameter mParameter : mBreakString) {
94 |
95 | String str = mParameter.getText();
96 |
97 | if (mParameter.getIsSmallOrLarge() == IS_SMALL) {
98 | paint.setTextSize(SMALL_TEXT);
99 |
100 | } else if (mParameter.getIsSmallOrLarge() == IS_LARGE) {
101 | paint.setTextSize(LARGE_TEXT);
102 | }
103 |
104 | if (mParameter.getIsRightOrLeft() == IS_RIGHT) {
105 | x = WIDTH - paint.measureText(str);
106 | } else if (mParameter.getIsRightOrLeft() == IS_LEFT) {
107 | x = START_LEFT;
108 | } else if (mParameter.getIsRightOrLeft() == IS_CENTER) {
109 | x = (WIDTH - paint.measureText(str)) / 2.0f;
110 | }
111 |
112 | if (str.isEmpty() | str.contains("\n") | mParameter.getIsSmallOrLarge() == IS_LARGE) {
113 | canvas.drawText(str, x, y + FontHeight / 2, paint);
114 | y = y + FontHeight;
115 | } else {
116 | canvas.drawText(str, x, y, paint);
117 | }
118 | y = y + FontHeight;
119 | }
120 | canvas.save(Canvas.ALL_SAVE_FLAG);
121 | canvas.restore();
122 | return bitmap;
123 | }
124 |
125 | /**
126 | * 合并图片
127 | */
128 | public static Bitmap addBitmapInHead(Bitmap first, Bitmap second) {
129 | int width = Math.max(first.getWidth(), second.getWidth());
130 | int startWidth = (width - first.getWidth()) / 2;
131 | int height = first.getHeight() + second.getHeight();
132 | Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
133 |
134 | for (int i = 0; i < result.getWidth(); i++) {
135 | for (int j = 0; j < result.getHeight(); j++) {
136 | result.setPixel(i, j, Color.WHITE);
137 | }
138 | }
139 | Canvas canvas = new Canvas(result);
140 | canvas.drawBitmap(first, startWidth, 0, null);
141 | canvas.drawBitmap(second, 0, first.getHeight(), null);
142 | return result;
143 | }
144 |
145 | /***
146 | * 使用两个方法的原因是:
147 | * logo标志需要居中显示,如果直接使用同一个方法是可以显示的,但是不会居中
148 | */
149 | public static Bitmap addBitmapInFoot(Bitmap bitmap, Bitmap image) {
150 | int width = Math.max(bitmap.getWidth(), image.getWidth());
151 | int startWidth = (width - image.getWidth()) / 2;
152 | int height = bitmap.getHeight() + image.getHeight();
153 | Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
154 |
155 | for (int i = 0; i < result.getWidth(); i++) {
156 | for (int j = 0; j < result.getHeight(); j++) {
157 | result.setPixel(i, j, Color.WHITE);
158 | }
159 | }
160 | Canvas canvas = new Canvas(result);
161 | canvas.drawBitmap(bitmap, 0, 0, null);
162 | canvas.drawBitmap(image, startWidth, bitmap.getHeight(), null);
163 | return result;
164 | }
165 |
166 | }
167 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fmx/list/string2bitmap/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.fmx.list.string2bitmap;
2 |
3 |
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.os.AsyncTask;
9 | import android.os.Bundle;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import android.widget.ImageView;
15 |
16 |
17 | import java.io.File;
18 | import java.io.IOException;
19 | import java.io.InputStream;
20 | import java.util.ArrayList;
21 |
22 | import static android.R.attr.width;
23 |
24 | /**
25 | * Created by Dpuntu on 2017/3/8.
26 | */
27 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
28 | private Button imageBtn;
29 | private ImageView mView;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_main);
35 | imageBtn = (Button) findViewById(R.id.p_image);
36 | mView = (ImageView) findViewById(R.id.s_image);
37 | imageBtn.setOnClickListener(this);
38 | }
39 |
40 | @Override
41 | public void onClick(View v) {
42 | switch (v.getId()) {
43 | case R.id.p_image:
44 | ImageTask mImageTask = new ImageTask();
45 | mImageTask.execute("");
46 | break;
47 | }
48 | }
49 |
50 | private class ImageTask extends AsyncTask {
51 | @Override
52 | protected Bitmap doInBackground(String... params) {
53 | return creatImage();
54 | }
55 |
56 | @Override
57 | protected void onPreExecute() {
58 | super.onPreExecute();
59 | imageBtn.setText("正在生成 - 请等待 不要着急");
60 | }
61 |
62 | @Override
63 | protected void onPostExecute(Bitmap bitmap) {
64 | super.onPostExecute(bitmap);
65 | imageBtn.setText("生成");
66 | mView.setImageBitmap(bitmap);
67 | }
68 | }
69 |
70 |
71 | private Bitmap creatImage() {
72 | try {
73 | InputStream ins = getAssets().open("res" + File.separator + "print.bmp");
74 | Bitmap imageBitmap = BitmapFactory.decodeStream(ins);
75 | ArrayList mParameters = new ArrayList<>();
76 |
77 | mParameters.add(new StringBitmapParameter("\n"));
78 | mParameters.add(new StringBitmapParameter("\n"));
79 | mParameters.add(new StringBitmapParameter("商户存根联"));
80 | mParameters.add(new StringBitmapParameter("用户名称(MERCHANT NAME):江苏东大集成电路系统工程技术有限公司"));
81 | mParameters.add(new StringBitmapParameter("\n"));
82 | mParameters.add(new StringBitmapParameter("商户编号(MERCHANT NO): 304301057328106"));
83 | mParameters.add(new StringBitmapParameter("终端编号(TEBMINAL NO): 00706937"));
84 | mParameters.add(new StringBitmapParameter("操作员号: 01"));
85 | mParameters.add(new StringBitmapParameter("卡号(CARD NO)"));
86 | mParameters.add(new StringBitmapParameter("12345678901212(C)", BitmapUtil.IS_RIGHT));
87 | mParameters.add(new StringBitmapParameter("\n"));
88 | mParameters.add(new StringBitmapParameter("发卡行(ISSUER):工商银行"));
89 | mParameters.add(new StringBitmapParameter("收单行(ACQUIRER):华夏银行"));
90 | mParameters.add(new StringBitmapParameter("交易类别(TXN TYPE):"));
91 | mParameters.add(new StringBitmapParameter(" 消费撤销(VOID)"));
92 | mParameters.add(new StringBitmapParameter("-------------------------"));
93 | mParameters.add(new StringBitmapParameter("持卡人签名CARD HOLDER SIGNATURE:"));
94 | mParameters.add(new StringBitmapParameter("\n"));
95 | mParameters.add(new StringBitmapParameter("\n"));
96 | mParameters.add(new StringBitmapParameter("\n"));
97 |
98 | mParameters.add(new StringBitmapParameter("模拟农行打印凭条", BitmapUtil.IS_CENTER, BitmapUtil.IS_LARGE));
99 | mParameters.add(new StringBitmapParameter("\n"));
100 | mParameters.add(new StringBitmapParameter("\n"));
101 | mParameters.add(new StringBitmapParameter("商户存根联 请妥善保管"));
102 | mParameters.add(new StringBitmapParameter("-------------------------"));
103 | mParameters.add(new StringBitmapParameter("用户名称(MERCHANT NAME):"));
104 | mParameters.add(new StringBitmapParameter("苏州农行直连测试商户", BitmapUtil.IS_RIGHT));
105 | mParameters.add(new StringBitmapParameter("商户编号(MERCHANT NO):"));
106 | mParameters.add(new StringBitmapParameter("113320583980037", BitmapUtil.IS_RIGHT));
107 | mParameters.add(new StringBitmapParameter("终端编号(TEBMINAL NO): 10300751"));
108 | mParameters.add(new StringBitmapParameter("操作员号(OPERATOR NO): 01"));
109 | mParameters.add(new StringBitmapParameter("-------------------------"));
110 | mParameters.add(new StringBitmapParameter("发卡行(ISSUER)"));
111 | mParameters.add(new StringBitmapParameter("农业银行", BitmapUtil.IS_RIGHT));
112 | mParameters.add(new StringBitmapParameter("收单行(ACQUIRER)"));
113 | mParameters.add(new StringBitmapParameter("农业银行", BitmapUtil.IS_RIGHT));
114 | mParameters.add(new StringBitmapParameter("卡号(CARD NO)"));
115 | mParameters.add(new StringBitmapParameter("12345678901212(C)", BitmapUtil.IS_RIGHT, BitmapUtil.IS_LARGE));
116 | mParameters.add(new StringBitmapParameter("卡有效期(EXP DATE) 2023/10"));
117 | mParameters.add(new StringBitmapParameter("交易类型(TXN TYPE)"));
118 | mParameters.add(new StringBitmapParameter("消费", BitmapUtil.IS_RIGHT, BitmapUtil.IS_LARGE));
119 | mParameters.add(new StringBitmapParameter("-------------------------"));
120 | mParameters.add(new StringBitmapParameter("交易金额未超过300.00元,无需签名"));
121 |
122 | ArrayList mParametersEx = new ArrayList<>();/**如果是空的列表,也可以传入,会打印空行*/
123 | mParametersEx.add(new StringBitmapParameter("\n"));
124 | mParametersEx.add(new StringBitmapParameter("\n"));
125 | mParametersEx.add(new StringBitmapParameter("\n"));
126 |
127 | Bitmap textBitmap = BitmapUtil.StringListtoBitmap(MainActivity.this, mParameters);
128 | Bitmap textBitmap2 = BitmapUtil.StringListtoBitmap(MainActivity.this, mParametersEx);
129 |
130 | Bitmap mergeBitmap = BitmapUtil.addBitmapInHead(imageBitmap, textBitmap);
131 |
132 | Bitmap mergeBitmap2 = BitmapUtil.addBitmapInFoot(mergeBitmap, imageBitmap);
133 | Bitmap mergeBitmap3 = BitmapUtil.addBitmapInFoot(mergeBitmap2, textBitmap2);
134 |
135 | Log.e("fmx", "argb_8888 = " + mergeBitmap3.getHeight() * mergeBitmap3.getWidth() * 32);
136 | Log.e("fmx", "rgb_565 = " + mergeBitmap3.getHeight() * mergeBitmap3.getWidth() * 16);
137 | return mergeBitmap3;
138 | } catch (IOException e) {
139 | e.printStackTrace();
140 | }
141 | return null;
142 | }
143 |
144 | }
145 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fmx/list/string2bitmap/StringBitmapParameter.java:
--------------------------------------------------------------------------------
1 | package com.fmx.list.string2bitmap;
2 |
3 | import android.support.annotation.Nullable;
4 |
5 | /**
6 | * Created by Dpuntu on 2017/3/8.
7 | */
8 |
9 | public class StringBitmapParameter {
10 | @Nullable
11 | private String text;
12 | private int isRightOrLeft;
13 | private int isSmallOrLarge;
14 |
15 | /**
16 | * @param text 字段
17 | */
18 | public StringBitmapParameter(String text) {
19 | this.text = text;
20 | this.isRightOrLeft = BitmapUtil.IS_LEFT;
21 | this.isSmallOrLarge = BitmapUtil.IS_SMALL;
22 | }
23 |
24 | /**
25 | * @param text 字段
26 | * @param isRightOrLeft 可空,默认右边
27 | */
28 | public StringBitmapParameter(String text, int isRightOrLeft) {
29 | this.text = text;
30 | this.isRightOrLeft = isRightOrLeft;
31 | this.isSmallOrLarge = BitmapUtil.IS_SMALL;
32 | }
33 |
34 | /**
35 | * @param text 字段
36 | * @param isRightOrLeft 可空,默认右边
37 | * @param isSmallOrLarge 可空,默认小字
38 | */
39 | public StringBitmapParameter(String text, int isRightOrLeft, int isSmallOrLarge) {
40 | this.text = text;
41 | this.isRightOrLeft = isRightOrLeft;
42 | this.isSmallOrLarge = isSmallOrLarge;
43 | }
44 |
45 | public String getText() {
46 | return text;
47 | }
48 |
49 | public void setText(String text) {
50 | this.text = text;
51 | }
52 |
53 | public int getIsRightOrLeft() {
54 | return isRightOrLeft;
55 | }
56 |
57 | public void setIsRightOrLeft(int isRightOrLeft) {
58 | this.isRightOrLeft = isRightOrLeft;
59 | }
60 |
61 | public int getIsSmallOrLarge() {
62 | return isSmallOrLarge;
63 | }
64 |
65 | public void setIsSmallOrLarge(int isSmallOrLarge) {
66 | this.isSmallOrLarge = isSmallOrLarge;
67 | }
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
21 |
22 |
26 |
27 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dpuntu/String2Bitmap/24ee0568481fb8f3d3ac485c0cc738023240d1f8/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dpuntu/String2Bitmap/24ee0568481fb8f3d3ac485c0cc738023240d1f8/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dpuntu/String2Bitmap/24ee0568481fb8f3d3ac485c0cc738023240d1f8/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dpuntu/String2Bitmap/24ee0568481fb8f3d3ac485c0cc738023240d1f8/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dpuntu/String2Bitmap/24ee0568481fb8f3d3ac485c0cc738023240d1f8/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | String2Bitmap
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/fmx/list/string2bitmap/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.fmx.list.string2bitmap;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------