我想將字符串中的文本轉換爲圖像,並將其顯示在ImageView
中,此外我想獲取在運行時創建的圖像的尺寸以供進一步使用。這是我從搜索中完成和使用的內容。Android text to image
tv = new TextView(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 60);
tv.setLayoutParams(layoutParams);
tv.setText("Some Text, can be long as much as required");
tv.setTextColor(Color.BLACK);
tv.setBackgroundColor(Color.WHITE);
Bitmap testB;
timer = new Timer();
timer.schedule(new TickerTask(), 1000,25);
testB = Bitmap.createBitmap(600, 20, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(testB);
tv.layout(0, 0, 380, 100);
tv.draw(c);
iv = (ImageView) findViewById(R.id.menuIcon);
iv.setLayoutParams(layoutParams);
iv.setBackgroundColor(Color.GREEN);
iv.setImageBitmap(testB);
問題: 參數不工作在代碼中設置。 轉換圖像後不顯示完整文字。
不是真的勸..如何使用背景圖片和不斷變化的文字..類似的ImageButton ..? – ngesh 2013-03-21 10:48:22
試試這個http://stackoverflow.com/questions/2801116/converting-a-view-to-bitmap-without-displaying-it-in-android – sinek 2013-03-21 10:48:26
我必須達到的任務需要將文本轉換爲圖像。我正在水平上對文本執行動畫,但無法檢測到文本已完全通過左側文本視圖的限制。完成後,圖像寬度可以幫助我在動畫上應用重新啓動 – 2013-03-21 10:51:03