1
我有一個應用程序,將創建的任何一個PNG圖像中的文本字段(自定義字體和顏色)用戶寫創建從一個TextView的圖像(而不失品位)
我在做什麼東西像這樣:
- 集字體,文字顏色和文本到一個TextView(BG是透明的)
用下面的代碼,生成圖像的TextView的
Bitmap returnedBitmap = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888); //Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); //Get the view's background Drawable bgDrawable =textView.getBackground(); if (bgDrawable!=null) //has background drawable, then draw it on the canvas bgDrawable.draw(canvas); // draw the view on the canvas view.draw(canvas); FileOutputStream out = null; out = new FileOutputStream(new File(filename)); returnedBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
的問題是,生成的圖像的質量沒有什麼是顯示在TextView中
有什麼辦法提高質量一樣嗎?
是因爲TextView沒有背景嗎?如果是這樣,是否有解決方法?需要生成的圖像僅是文本,因此透明背景
感謝
你可以採取截圖 http://stackoverflow.com/a/5651242/3257513 – Yoni
試試'textview.setDrawingCacheEnabled(true); 位圖位圖= Bitmap.createBitmap(textview.getDrawingCache()); textview.setDrawingCacheEnabled(false);' –
您的位圖大小取決於textView的寬度和高度,它取決於屏幕度量標準(除了文本和textSize的長度)。例如,對於mdpi,您將擁有100像素高度位圖和xhdpi 200像素高度。你接受這個概念嗎?或者你想以嚴格的高度返回位圖(只依賴於textSize)? –