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; }
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);
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);
TextView textV = new TextView(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(128, 128); textV.setLayoutParams(layoutParams); textV.setTextColor(Color.WHITE); textV.setBackgroundColor(Color.TRANSPARENT); textV.setGravity(Gravity.CENTER); textV.setText(text); textV.setDrawingCacheEnabled(true); Bitmap b = Bitmap.createBitmap( textV.getLayoutParams().width, textV.getLayoutParams().height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); textV.layout(0, 0, textV.getLayoutParams().width, textV.getLayoutParams().height); textV.draw(c); textV.setDrawingCacheEnabled(false);
public void run() { tv.setDrawingCacheEnabled(true); tv.buildDrawingCache();
send = (Button) findViewById(R.id.button); tv1 = (TextView) findViewById(R.id.outputc); tv1.setDrawingCacheEnabled(true);
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; }
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(); }
// 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); }
tv.setGravity(Gravity.BOTTOM); tv.setPadding(8, 8, 8, 50); tv.setDrawingCacheEnabled(true); tv.measure(MeasureSpec.makeMeasureSpec(canvas.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec( tv.setDrawingCacheEnabled(false); iv.setDrawingCacheEnabled(false); parent.setDrawingCacheEnabled(false);
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);
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; }
-textView.getScrollY()); textView.draw(canvas); textView.setDrawingCacheEnabled(true); Bitmap cacheBmp = textView.getDrawingCache(); Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888,
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);