我有一个应用程序,用户插入文本后,点击按钮,它会生成一个新的图片,其中包含预设图像中的该文本,并将其保存在手机上。
但是有时候文本太长了,超过了图片的宽度,因此我想要把它分成一行。我应该怎么做?
我尝试使用breakText,但不确定如何使用它...我正在使用:
textPaint.breakText(text[2], true, bmp.getWidth(), null);
但它没有起作用。
此外,当我手动在EditText处换行时,它只显示一行并在第二行应该开始的位置上显示"[]"...
编辑:我的原始代码:
private void SaveMyImage() {
// TODO Auto-generated method stub
File myDir = new File(Environment.getExternalStorageDirectory().getPath()+"/App/");
myDir.mkdirs();
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
Canvas canvas = new Canvas(bmp);
Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
if (text[0].equals("Image 01")) {
textPaint.setColor(Color.BLACK);
}
else {
textPaint.setColor(Color.WHITE);
}
textPaint.setTextAlign(Align.CENTER);
textPaint.setTextSize(tamanho);
textPaint.setShadowLayer(2, 2, 2, Color.BLACK);
textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text Overlapping Pattern
canvas.drawBitmap(bmp, 0, 0, null);
canvas.drawText(text[1], largura, altura2, textPaint);
canvas.drawText(text[2], largura, altura, textPaint);
bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
Toast.makeText(SaveIMG.this, "Image saved on phone", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/App/"+fname);
pronto.setImageURI(uri);
}