Note that there are some explanatory texts on larger screens.

plurals
  1. POScreen capture TextureView is black using DrawingCache
    text
    copied!<p>I have a custom tiling view, which was until recently based on a SurfaceView. I have now changed it to extend TextureView.</p> <p>Basically I am getting a large image in tile bits.</p> <p>I need to capture all the content of the screen and save it as a bitmap, which has worked with all views including the SurfaceView. However, when i use the same method now, the area of the TextureView is black. I have read that this has something to do with HW acceleration.</p> <p>Is there any way of capturing the image of the texture view? Below is the screen capture method.</p> <pre><code>public File takeScreenShot(View contentView) { File result = null; String mPath = this.cacheDir + "/screenshot.png"; File imageFile = new File(mPath); if (imageFile.exists()) { imageFile.delete(); Log.i("ImageManager","Old screenshot image was deleted"); } // create bitmap screen capture Bitmap bitmap; View v1 = contentView; v1.setDrawingCacheEnabled(true); v1.setDrawingCacheBackgroundColor(Color.WHITE); bitmap = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); OutputStream outputStream = null; try { outputStream = new FileOutputStream(imageFile); bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream); outputStream.flush(); outputStream.close(); result = imageFile; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; } </code></pre> <p>EDIT: New attempt Get all TextureViews and call getBitmap. This works, however placing them on top of the larger bitmap does not look right with the coordinates from the TilingView it self or the getLocation OnScreen() or getLocationInWindow().</p> <pre><code>public List&lt;TilingTextureView&gt; getAllTextureViews(View view) { List&lt;TilingTextureView&gt; tilingViews = new ArrayList&lt;TilingTextureView&gt;(); if (view instanceof TilingTextureView) { tilingViews.add((TilingTextureView)view); } else if(view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup)view; for (int i = 0; i &lt; viewGroup.getChildCount(); i++) { tilingViews.addAll(getAllTextureViews(viewGroup.getChildAt(i))); } } return tilingViews; } </code></pre> <p>This bit is added in the takeScreenShot method after getting the screen shot of the entire view.</p> <pre><code>List&lt;TilingTextureView&gt; tilingViews = getAllTextureViews(contentView); if (tilingViews.size() &gt; 0) { Canvas canvas = new Canvas(bitmap); for (TilingTextureView tilingTextureView : tilingViews) { Bitmap b = tilingTextureView.getBitmap(tilingTextureView.getWidth(), tilingTextureView.getHeight()); int[] location = new int[2]; tilingTextureView.getLocationInWindow(location); int[] location2 = new int[2]; tilingTextureView.getLocationOnScreen(location2); canvas.drawBitmap(b, location[0], location[1], null); } } </code></pre>
 

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