I\'m using drawables like the following one for backgrounds with a gradient:
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>
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:
Or simply turn this option on when creating new AVDs.
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.
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/