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

◇◆丶佛笑我妖孽 提交于 2019-11-30 20:26:57

Just to make sure everyone who reads this question sees the solution:

As davehale23 and Chris Stratton pointed out, the problem is not Eclipse or the app being "photographed". The problem is the Android emulator, which obviously uses a reduced bit depth.

So if one takes screenshots of an app, one should always use a real device.

As @Marco W. has mentioned above the issue directly relates to the Android Eclipse Emulator.

Therefore in the newer versions of Eclipse SDK the solution for improved image quality (and possibly better emulator performance) is to enable 'Use Host GPU' in the Android Device Manager emulation option.

To turn this on for existing AVDs:

  • Select the AVD name you want to enable GPU emulation for
  • Click 'Edit'
  • Check 'Use Host GPU' under the Emulation Options section
  • Click 'OK' to save your AVD configuration changes

Or simply turn this option on when creating new AVDs.

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:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
Rolz73

I believe that the screenshot bitdepth issue is a fault of 2 parties; Android DDMS/monitor as well as the device/emulator being captured.

If a device/emulator has a low bitdepth display, then there is nothing you do about that particular situation (GIGO). Although, I have clearly seen that on some devices/emulators, the screen capture quality that DDMS takes is lower than the actual display.

In my hunt, I have just found an application that I think solves this problem called "Android Screen Monitor" that you can obtain here:

http://code.google.com/p/android-screen-monitor/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!