Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to draw outside canvas and make bitmap of it?
    primarykey
    data
    text
    <p>I am drawing some rows of text. After a couple of rows, it goes offscreen. What i want to do is capture all the rows(also the rows outside the canvas) in a bitmap.</p> <pre><code>I have the code below which only works for within the canvas(screen). private class DeciderView extends View { private Paint paint; String text = ""; String[] options = { "een", "twee", "drie", "vier", "vijf", "zes", "zeven", "acht", "negen", "tien", "elf", "twaalf", "dertien", "vertien", "vijftien" }; public DeciderView(Context context) { super(context); // Keep screen on getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Remove title bar requestWindowFeature(Window.FEATURE_NO_TITLE); // Remove notification bar getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); this.setBackgroundColor(Color.WHITE); paint = new Paint(); paint.setTextSize(75); paint.setColor(Color.BLACK); paint.setStrokeWidth(10); paint.setAntiAlias(true); setDrawingCacheEnabled(true); setDrawingCacheQuality(DRAWING_CACHE_QUALITY_HIGH); } private void drawInput(Canvas canvas) { Paint p = new Paint(); p.setTextAlign(Align.CENTER); p.setTextSize(canvas.getWidth() / 10f); p.setColor(Color.BLACK); float xText = canvas.getWidth() / 2f; float yText = (canvas.getHeight() / 4f); for (int i = 0; i &lt; options.length; i++) { text += options[i] + "\n"; } for (String line : text.split("\n")) { canvas.drawText(line, xText, yText, p); yText -= (p.ascent() + p.descent()) * 2.5f; } } @Override public void onDraw(Canvas canvas) { drawInput(canvas); this.setDrawingCacheEnabled(true); Bitmap b = Bitmap.createBitmap(this.getDrawingCache()); b = Bitmap.createScaledBitmap(b, canvas.getWidth(), canvas.getHeight(), false); try { b.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream( new File(Environment.getExternalStorageDirectory().getPath() + "/Pictures/aaaaa.jpg"))); } catch (FileNotFoundException e) { e.printStackTrace(); } if (b != null) { b.recycle(); b = null; } } } </code></pre> <p>So basically i want to make a bitmap from all the rows, even if the rows are drawn outside the canvas.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload