Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

android - How to capture screenshot of surfaceview with background

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 along with background.please help me how to solve this issue.

         View content  = findViewById(R.id.relative21);
        content.setDrawingCacheEnabled(true);

        SurfaceHolder sfhTrack = drawingSurface.getHolder();
              sfhTrack.setFormat(PixelFormat.TRANSPARENT);

               private void getScreen() {
          // TODO Auto-generated method stub

             View content = findViewById(R.id.relative21);
                Bitmap bitmap = content.getDrawingCache();
            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);
                    bitmap.compress(CompressFormat.PNG, 100, ostream);
                    ostream.close();
                } 
                catch (Exception e) 
                {
                    e.printStackTrace();
                }
    }

i tried above code i am able to save background but i am not able save which is drawn.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
   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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...