我在我的Android应用程序中使用相机,但我必须添加文本以保存捕获的图像(捕获图像应用程序后应该要求添加文本以保存捕获的图像)。我怎样才能做到这一点 ?
答案 0 :(得分:0)
我认为你要做的是用图像保存一张纸条。 您应该创建一个目录,在该目录中将使用名称“image ****。jpg”保存图像。在同一目录中创建一个具有相同名称但在扩展名上具有不同扩展名的文件。 (如“image ****。txt”)。
访问图像文件时,请单独打开注释文件并进行处理。
答案 1 :(得分:0)
尝试将文字写入相机的位图......
private Bitmap writeTextBitmap(Bitmap bitmap,String text) {
Typeface tf = Typeface.create("Helvetica", Typeface.BOLD);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.WHITE);
paint.setTypeface(tf);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(20);
Rect textRect = new Rect();
paint.getTextBounds(text, 0, text.length(), textRect);
Canvas canvas = new Canvas(bitmap);
//If the text is bigger than the canvas , reduce the font size
if(textRect.width() >= (canvas.getWidth() - 4)) //the padding on either sides is considered as 4, so as to appropriately fit in the text
paint.setTextSize(convertToPixels(mContext, 7)); //Scaling needs to be used for different dpi's
//Calculate the positions
int xPos = (canvas.getWidth() / 2) - 2; //-2 is for regulating the x position offset
//"- ((paint.descent() + paint.ascent()) / 2)" is the distance from the baseline to the center.
int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)) ;
canvas.drawText(text, xPos, yPos, paint);
return bitmap;
}