Taking screen shot of a SurfaceView in android

后端 未结 4 961
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 19:30

I am using following method to taking screen shot of a particular view which is a SurfaceView.

public void takeScreenShot(View surface_view){

    // create          


        
4条回答
  •  失恋的感觉
    2020-12-09 20:24

    Surface view is a view but item on surface view like bitmap or other object are not any view. So while you capture surface view it will capture every thing on the surface. You have to use other view like image view or other above the surface view and then capture those view.

    First get the view whose picture want to take then do this

                Bitmap bitmap;
                View rv = **your view**
                rv.setDrawingCacheEnabled(true);
                bitmap = Bitmap.createBitmap(rv.getDrawingCache());
                rv.setDrawingCacheEnabled(false);
    
                // Write File to internal Storage
    
                String FILENAME = "captured.png";
                FileOutputStream fos = null;
    
                try {
    
                    fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
    
                } catch (FileNotFoundException e1) {
    
                    e1.printStackTrace();
                    Log.v("","FileNotFoundException: "+e1.getMessage());
    
                }
    
                try {
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
                    fos.flush();
                    fos.close();
    
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } 
    

提交回复
热议问题