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; }
public void onClick(View v) { tv1.buildDrawingCache(); iv.setImageBitmap(tv1.getDrawingCache()); outputc.setText((inputc.getText()));
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(); }
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; }