android.widget.TextView.getDrawingCache()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中android.widget.TextView.getDrawingCache()方法的一些代码示例,展示了TextView.getDrawingCache()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getDrawingCache()方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getDrawingCache

TextView.getDrawingCache介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public Drawable createFromView(int positionNumber)
{
  LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
  View view = inflater.inflate(R.drawable.pin_icon, null, false);
  TextView tv = (TextView) view.findViewById(R.id.pin_background);
  tv.setText("     "+ (positionNumber+1) );   // +1 since position is starting from 0
  tv.setDrawingCacheEnabled(true);
  tv.layout(0, 0, 50, 50);
  tv.buildDrawingCache();
  Bitmap b = Bitmap.createBitmap(tv.getDrawingCache());
  tv.setDrawingCacheEnabled(false);
  Drawable d = new BitmapDrawable(b);
  return d;
}

代码示例来源:origin: stackoverflow.com

TextView yourView = new TextView(this);
yourView.setText("text");
yourView.setBackgroundResource(R.drawable.background_resource);

// taken from the other ticket
Bitmap snapshot = null;
Drawable drawable = null;
yourView.setDrawingCacheEnabled(true);
yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); //Quality of the snpashot
try {
  snapshot = Bitmap.createBitmap(yourView.getDrawingCache(), sizes and stuff); // You can tell how to crop the snapshot and whatever in this method
  drawable = new BitmapDrawable(snapshot)
} finally {
  yourView.setDrawingCacheEnabled(false);
}

mySeekBar.setThumb(drawable);

代码示例来源:origin: stackoverflow.com

tv.buildDrawingCache();
Bitmap bm = tv.getDrawingCache();

代码示例来源:origin: stackoverflow.com

Paint paint1 = new Paint();
paint1.setStyle(Paint.Style.FILL);
paint1.setAntiAlias(true);
paint1.setColor(Color.BLACK);
paint1.setTextSize(15);

TextView tv = new TextView(context);
tv.setTextColor(Color.BLACK);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.setMargins(5, 2, 0, 0); // llp.setMargins(left, top, right, bottom);
tv.setLayoutParams(llp);
tv.setTextSize(10);
String text="this is good to see you , i am the king of the team";

tv.setText(text);
tv.setDrawingCacheEnabled(true);
tv.measure(MeasureSpec.makeMeasureSpec(canvas.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(canvas.getHeight(), MeasureSpec.EXACTLY));
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
canvas.drawBitmap(tv.getDrawingCache(), 5, 10, paint1);
tv.setDrawingCacheEnabled(false);

代码示例来源:origin: stackoverflow.com

iv.setImageBitmap(tv1.getDrawingCache());
outputc.setText((inputc.getText()));

代码示例来源:origin: easemob/kefu-android-demo

private Bitmap creatCodeBitmap(String contents, int width, int height, Context context) {
  TextView tv = new TextView(context);
  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
      LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  tv.setLayoutParams(layoutParams);
  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;
}

代码示例来源:origin: stackoverflow.com

EditText editText = (EditText) findViewById(R.id.editText);
TextView textView = new TextView(this.getApplicationContext());

textView.setTypeface(editText.getTypeface());
textView.setText(editText.getText());
textView.measure(
  View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),
  View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
textView.setDrawingCacheEnabled(true);
textView.buildDrawingCache();

Bitmap b = textView.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
textView.destroyDrawingCache();

try{
  String path = Environment.getExternalStorageDirectory().toString() + "/picture.png";
  OutputStream outputStream = new FileOutputStream(new File(path));
  b.compress(Bitmap.CompressFormat.PNG, 0, outputStream);
  outputStream.flush();
  outputStream.close();
} catch (Exception e) {
  e.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

// String to bitmap 
 public Bitmap StringToBitMap(String encodedString){
     TextView textView = new TextView(StoryActivity.this); 
     textView.layout(30, 300, 300, 500);
     textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 12);
     textView.setTextColor(Color.BLACK);
     textView.setText(encodedString); 
     textView.setDrawingCacheEnabled(true); 
     textView.setDrawingCacheQuality(2);
     return Flip(textView.getDrawingCache()) ;
 }
 // flip picture
 private Bitmap Flip(Bitmap asset) {
     Matrix mat = new Matrix();
     mat.postScale(-1F, 1F); 
     int width = asset.getWidth();
     int height = asset.getHeight();
     return Bitmap.createBitmap(asset, 0, 0, width, height, mat, true);
 }

代码示例来源:origin: pchauhan/EdittextWithTag

textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);

代码示例来源:origin: AmaldevTA/ChipLayout

private SpannableStringBuilder textToChip(String val, boolean trim){
  SpannableStringBuilder ssb = new SpannableStringBuilder(val);
  try{
    TextView textView = createAutoCompleteTextView(context);
    if (trim){
      textView.setText(val.substring(0, ChipLayout.MAX_CHARACTER_COUNT)+"..");
    }else {
      textView.setText(val);
    }
    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(),textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(),textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();
    BitmapDrawable bmpDrawable = new BitmapDrawable(context.getResources(), viewBmp);
    bmpDrawable.setBounds(0, 0, bmpDrawable.getIntrinsicWidth(), bmpDrawable.getIntrinsicHeight());
    ssb.setSpan(new ImageSpan(bmpDrawable), 0, val.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  }catch (Exception e){}
  return ssb;
}

代码示例来源:origin: stackoverflow.com

textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888,
    true);

代码示例来源:origin: stackoverflow.com

TextView textView = (TextView) lf.inflate(R.layout.chips_edittext, null);
     textView.setText(c); // set text
     int image = ((ChipsAdapter) getAdapter()).getImage(c);
     textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, image, 0);
     // capture bitmapt of genreated textview
     int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
     textView.measure(spec, spec);
     textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
     Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(),Bitmap.Config.ARGB_8888);
     Canvas canvas = new Canvas(b);
     canvas.translate(-textView.getScrollX(), -textView.getScrollY());
     textView.draw(canvas);
     textView.setDrawingCacheEnabled(true);
     Bitmap cacheBmp = textView.getDrawingCache();
     Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
     textView.destroyDrawingCache();  // destory drawable
     // create bitmap drawable for imagespan
     BitmapDrawable bmpDrawable = new BitmapDrawable(viewBmp);
     bmpDrawable.setBounds(0, 0,bmpDrawable.getIntrinsicWidth(),bmpDrawable.getIntrinsicHeight());
     // create and set imagespan 
     ssb.setSpan(new ImageSpan(bmpDrawable),x ,x + c.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

相关文章

TextView类方法