我在 android 应用程序中有文本到图像的代码,它成功地将文本转换为图像并保存到 SD 卡中的本地位置。我面临的问题是它没有将完整的文本转换为图像。这是我提供给 textview 的文本“这是 t ashdf asdhfj sdhkfh shd jshd hsdhfsdjkhfksdjfhsdlhfksldhfklh shdkfjhsdkj hfsdjk kdjhfsk djhfskldh shdjkfhk sjhdfkh”。这是它转换为图像的内容
这是我的代码
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 60);
tv.setLayoutParams(layoutParams);
tv.setText("this is t ashdf asdhfj sdhkfh shd jshd hsdhfsdjkhfksdjfhsdlhfksldhfklh shdkfjhsdkj hfsdjk kdjhfsk djhfskldh shdjkfhk sjhdfkh ");
tv.setTextColor(Color.BLACK);
tv.setBackgroundColor(Color.WHITE);
Bitmap testB;
timer = new Timer();
timer.schedule(new TickerTask(), 1000,25);
testB = Bitmap.createBitmap(tv.getText().length(), 20, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(testB);
tv.layout(0, 0, 800, 30);
tv.draw(c);
iv = (ImageView) findViewById(R.id.menuIcon);
x=40;
iv.setPadding(x, 0, 0, 0);
iv.setLayoutParams(layoutParams);
iv.setBackgroundColor(Color.GREEN);
iv.setImageBitmap(testB);
iv.setDrawingCacheEnabled(true);
BitmapDrawable drawable = (BitmapDrawable) iv.getDrawable();
Bitmap bitmap = drawable.getBitmap();
//Bitmap bitmap = testB;
File sdCardDirectory = Environment.getExternalStorageDirectory();
File image = new File(sdCardDirectory, "test.png");
boolean success = false;
// Encode the file as a PNG image.
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
success = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (success) {
Toast.makeText(getApplicationContext(), "Image saved with success"+tv.getText().length(),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error during image saving", Toast.LENGTH_LONG).show();
}