@Override public void draw(Canvas canvas) { canvas.translate(mOffsetLeft / 2, mOffsetTop / 2); super.draw(canvas); } }
view.draw(canvas); canvas.restore();
public void drawInternal(@NonNull Canvas canvas) { super.draw(canvas); if (stroke != null) drawStroke(canvas); if (rippleDrawable != null && rippleDrawable.getStyle() == RippleDrawable.Style.Over) rippleDrawable.draw(canvas); }
canvas.translate(rectPrimary.centerX() - (measurementWidthText.getWidth() / 2), rectPrimary.top - measurementWidthText.getHeight() - measurementTextOffset); measurementWidthText.draw(canvas); canvas.restore(); canvas.translate(rectPrimary.right + measurementTextOffset, rectPrimary.bottom - (rectPrimary.height() / 2) - (measurementHeightText.getHeight() / 2)); measurementHeightText.draw(canvas); canvas.restore(); canvas.translate(rectSecondary.centerX() - measurementHeightText.getWidth() / 2, (rectPrimary.bottom + rectSecondary.top) / 2 - (measurementHeightText.getHeight() / 2)); measurementHeightText.draw(canvas); canvas.restore(); canvas.translate((rectPrimary.right + rectSecondary.left) / 2 - (measurementWidthText.getWidth() / 2), rectSecondary.centerY() - measurementWidthText.getHeight() / 2); measurementWidthText.draw(canvas); canvas.restore(); canvas.translate(rectSecondary.centerX() - measurementHeightText.getWidth() / 2, (rectPrimary.top + rectSecondary.bottom) / 2 - (measurementHeightText.getHeight() / 2)); measurementHeightText.draw(canvas); canvas.restore(); canvas.translate((rectPrimary.left + rectSecondary.right) / 2 - (measurementWidthText.getWidth() / 2), rectSecondary.centerY() - measurementWidthText.getHeight() / 2); measurementWidthText.draw(canvas); canvas.restore();
@Override public void draw(Canvas canvas) { canvas.translate(mOffsetLeft / 2, mOffsetTop / 2); super.draw(canvas); } }
TextView textView = new TextView(getContext()); int width = (int) (rect.right - rect.left); int height = (int) (rect.bottom - rect.top); textView.layout(0, 0, width, height); textView.setText(e.getSummary()); Bitmap bitmapText = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvasText = new Canvas(bitmapText); textView.draw(canvasText); canvas.drawBitmap(bitmapText, rect.left, rect.top, null);
@Override public void draw(Canvas canvas) { super.draw(canvas); mBadgeDrawable.draw(canvas); }
TextView usertext = new TextView(this); usertext.setText("Hi Hello"); usertext.setTextSize(22); usertext.setBackgroundColor(Color.TRANSPARENT); Bitmap testB; testB = Bitmap.createBitmap(TextLayout.getWidth(), TextLayout.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(testB); usertext.layout(0, 0, 80, 100); usertext.draw(c); // create imageview in layout file and declare here Imageview iv = (Imageview) findviewByid(your imageview id) iv.setImageBitmap(testB); iv.setOnTouchListener(this);
// ... PdfDocument.Page page = document.startPage(pageInfo); TextView textView = new TextView(ctx); textView.setText("1,2,3"); // here the solution int left = 0; int top = 0; int width = 200; int height = 200; textView.layout(0,0,width,height); canvas.save() canvas.translate(left,top); textView.draw(page.getCanvas()); canvas.restore()
@Override public void draw(Canvas canvas) { if (hasFocus()) { super.getDrawingRect(mRect); mBound.set(-borderSize + mRect.left, -borderSize + mRect.top, borderSize + mRect.right, borderSize + mRect.bottom); mBorderDrawable.setBounds(mBound); canvas.save(); if (mBorderDrawable != null) mBorderDrawable.draw(canvas); canvas.restore(); } super.draw(canvas); }
TextView textView = new TextView(getContext()); textView.setText(DetailsActivity.temp_desc); textView.setMinLines(1); canvas.translate(0,bitmap.getHeight()); textView.layout(0, 0, 500, 150); textView.draw(canvas);
private Bitmap loadBitmap(int width, int height, int index) { Bitmap txtBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); String text1 = yourPagesStringArray[index]; Canvas c = new Canvas(txtBitmap); TextView tv = new TextView(getApplicationContext()); tv.setText(text1); tv.setTextColor(0xa00050ff); tv.setTextSize(15); tv.setLinksClickable(true); tv.setLineSpacing(2, 2); tv.layout(0, 0, getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels); tv.draw(c); c.drawBitmap(txtBitmap, 0, 0, null); return txtBitmap; }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(80, 100); tv.setLayoutParams(layoutParams); tv.setText("testing 1 2 3"); tv.setTextColor(Color.BLACK); tv.setBackgroundColor(Color.TRANSPARENT); Bitmap testB; testB = Bitmap.createBitmap(80, 100, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(testB); tv.layout(0, 0, 80, 100); tv.draw(c); ImageView iv = new ImageView(this); iv.setLayoutParams(layoutParams); iv.setBackgroundColor(Color.GRAY); iv.setImageBitmap(testB); setContentView(iv); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = new TextView(this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(80, 100); tv.setLayoutParams(layoutParams); tv.setText("testing 1 2 3"); tv.setTextColor(Color.BLACK); tv.setBackgroundColor(Color.TRANSPARENT); Bitmap testB; testB = Bitmap.createBitmap(80, 100, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(testB); tv.layout(0, 0, 80, 100); tv.draw(c); ImageView iv = (ImageView)findViewById(R.id.menuIcon); iv.setLayoutParams(layoutParams); iv.setBackgroundColor(Color.GRAY); iv.setImageBitmap(testB); iv.setMaxHeight(80); iv.setMaxWidth(80); }
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);
TextView upTextView = (TextView) getLayoutInflater().inflate( R.layout.up_text, null); upTextView.setText("CITIES"); upTextView.measure(0, 0); upTextView.layout(0, 0, upTextView.getMeasuredWidth(), upTextView.getMeasuredHeight()); Bitmap bitmap = Bitmap.createBitmap(upTextView.getMeasuredWidth(), upTextView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); upTextView.draw(canvas); BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
private static Bitmap renderTextIntoBitmap(Context context, Bitmap.Config bitmapConfig, String text, int textColor, int maxTextWidth) { LayoutInflater inflater = LayoutInflater.from(context); TextView tv = (TextView) inflater.inflate(R.layout.just_a_textview, null); tv.setText(text); tv.setMaxWidth(maxTextWidth); int widthSpec = View.MeasureSpec.makeMeasureSpec(maxTextWidth, View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); tv.measure(widthSpec, heightSpec); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.setTextColor(textColor); Bitmap bitmap = Bitmap.createBitmap(tv.getWidth(), tv.getHeight(), bitmapConfig); Canvas canvas = new Canvas(bitmap); tv.draw(canvas); return bitmap; }
private static Bitmap captureTextBitmap(TextView textView) { Drawable background = textView.getBackground(); textView.setBackground(null); int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight(); int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom(); if (width == 0 || height == 0) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop()); textView.draw(canvas); textView.setBackground(background); return bitmap; }
private static Bitmap captureTextBitmap(TextView textView) { Drawable background = textView.getBackground(); textView.setBackground(null); int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight(); int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom(); if (width == 0 || height == 0) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop()); textView.draw(canvas); textView.setBackground(background); return bitmap; }
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);