先说说自己的思路(有什么欠缺的望喷。。。)
1、在xml 文件写入Imageview(用来显示拍照图片) 和textview (显示想要显示的文字)
2、将xml 布局通过 LayoutInflater.from(context).inflate转换为view视图
3、将view 视图通过Bitmap.createBitmap 转为bitmap 对象
4、最后让其显示在imageview 上
不多说直接撸一段 ,有什么不足多多留言。
public class ImagerTextUtils {
public Bitmap bitmap;
/*
x -----要显示的图片的宽
y -----要显示的图片的高
bitmap ---传入相机拍照后的图片,返回带文字的图片
layout ----加载图片和文字的布局
* */
public Bitmap getBitmap(Context context, int layout, int x, int y, Bitmap bitmap) {
View view = LayoutInflater.from(context).inflate(layout, null);
ImageView imageView = view.findViewById(R.id.imager1);//显示拍照后的图片
imageView.setImageBitmap(bitmap);
TextView textView = view.findViewById(R.id.text3);//显示的文字
textView.setText("成功了");
//调用这个方法可以使得到的bitmap不为null
view.measure(View.MeasureSpec.makeMeasureSpec(x, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(y, View.MeasureSpec.EXACTLY));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
}
return 后的bitmap 就是我们要显示的bitmap .