2

在我的应用程序中,我想捕获带有surfaceview的屏幕,但我无法捕获使用背景绘制的屏幕。如何保存与背景一起绘制的屏幕。请帮助我如何解决这个问题。

         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();
                }
    }

我尝试了上面的代码,我能够保存背景,但我无法保存绘制的。

4

1 回答 1

2
   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();
        }
    }

通过重叠两个位图,我在一个位图中解决了这个问题,我捕获了背景,在第二个位图中我捕获了表面视图,我在这两个位图中都重叠了,我得到了解决方案。

于 2012-07-26T05:34:12.643 回答