How to capture screenshot of surfaceview with background

前端 未结 1 945
[愿得一人]
[愿得一人] 2020-12-15 14:51

in my application i want to capture screen which is with surfaceview but i am not able capture screen on which is drawn with background.how to save the screen with drawn a

相关标签:
1条回答
  • 2020-12-15 15:10
       public static Bitmap overlay(Bitmap bmp1,Bitmap bmp2) {
            Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(),      bmp1.getConfig());
            Canvas canvas = new Canvas(bmOverlay);
            canvas.drawBitmap(bmp1, 0,0, null);
    
            canvas.drawBitmap(bmp2, 0, 0, null);
            Log.i("bmOverlay.......",""+bmOverlay);
            bmp3=bmOverlay;
            return bmOverlay;
        }
    
           private void getScreen() {
            Toast.makeText(BookType1.this, "saved", Toast.LENGTH_SHORT).show();
              File myDir=new File("/sdcard/saved_images");
                myDir.mkdirs();
                Random generator = new Random();
                int n = 10000;
                n = generator.nextInt(n);
                String fname = "Image-"+ n +".png";
                File file = new File (myDir, fname);
    
    
            try 
            {
    
                FileOutputStream ostream = new FileOutputStream(file);
                bmp3.compress(CompressFormat.PNG, 100, ostream);
    
    
                ostream.close();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }
        }
    

    By overlapping two bitmaps i solved this issue in one bitmap i captured background and in second bitmap i captured surface view and i overlapped both in this i got solution.

    0 讨论(0)
提交回复
热议问题