List of usage examples for android.widget TextView buildDrawingCache
@Deprecated public void buildDrawingCache()
Calling this method is equivalent to calling buildDrawingCache(false)
.
From source file:Main.java
protected static Bitmap creatCodeBitmap(String contents, int width, int height, Context context) { TextView tv = new TextView(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); tv.setLayoutParams(layoutParams);/*from ww w .j a v a 2 s . c o m*/ tv.setText(contents); tv.setHeight(height); tv.setGravity(Gravity.CENTER_HORIZONTAL); tv.setWidth(width); tv.setDrawingCacheEnabled(true); tv.setTextColor(Color.BLACK); tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.buildDrawingCache(); Bitmap bitmapCode = tv.getDrawingCache(); return bitmapCode; }
From source file:com.example.SmartBoard.DrawingView.java
public Bitmap textToBitmap(String text, int color, float posX, float posY, int size) { TextView textView = new TextView(getContext()); textView.setVisibility(View.VISIBLE); textView.setTextColor(color);//from w w w .jav a2 s . c o m textView.setMaxWidth(500); textView.setMaxHeight(500); textView.setMaxLines(4); textView.setX(posX); textView.setY(posY); textView.setText(text); textView.setTextSize(size); LinearLayout layout = new LinearLayout(getContext()); layout.addView(textView); layout.measure(500, 500); layout.layout(0, 0, 500, 500); textView.setDrawingCacheEnabled(true); textView.buildDrawingCache(); Bitmap bm = textView.getDrawingCache(); return bm; }