Android's gradient drawables: poor quality of screenshots in Eclipse

前端 未结 4 671
生来不讨喜
生来不讨喜 2021-01-05 17:12

I\'m using drawables like the following one for backgrounds with a gradient:




        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 17:52

    Furthering my comment above, try something like this, I usually get pretty good quality from this, although haven't noticed what gradients look like. The DRAWING_CACHE_QUALITY_HIGH may help, not sure.

    void getScreenCap(View yourView) {
        yourView.setDrawingCacheEnabled(true);
        yourView.setDrawingCacheQuality(LinearLayout.DRAWING_CACHE_QUALITY_HIGH);
        yourView.buildDrawingCache();
        Bitmap bmp = null;
        if (yourView != null) { 
            try {
                bmp = Bitmap.createBitmap(yourView.getDrawingCache());
            } catch (NullPointerException e) { }
        }
        yourView.setDrawingCacheEnabled(false);
        yourView.destroyDrawingCache();
    
        if (bmp != null) {
            String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
            File dir = new File(file_path);
            if (!dir.exists()) { 
                dir.mkdirs();
            }
            File file = new File(dir, "screencap.png");
            FileOutputStream fOut = null;
            try { fOut = new FileOutputStream(file); } catch (FileNotFoundException e1) { }
            bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
            try { fOut.flush(); fOut.close(); } catch (IOException e1) { }
        }
    }
    

    I'm not sure if this will compile, but it has the stuff you would need to take a screen cap of your app.

    Your AVD needs an SDCARD and in your manifest you also need:

    
    

提交回复
热议问题