6

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

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient
        android:startColor="#ffffff"
        android:endColor="#cccccc"
        android:angle="-90"
        android:dither="true" />
</shape>

This results in a banded gradient on the emulator, and when I take a screenshot of the emulator (using Eclipse), the result is even poorer:

enter image description here

Why? And how to solve this problem? It is although I'm using android:dither="true" in the drawables' XML and setting this in the Activity's onCreate():

    getWindow().setFormat(PixelFormat.RGBA_8888);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

By the way, the blue part is the native action bar and the grey gradients are ListView rows with the background drawable.

caw
  • 30,999
  • 61
  • 181
  • 291
  • What version of Eclipse? – davehale23 Nov 27 '12 at 15:53
  • Eclipse SDK 3.7.2, Android Tools 20.0.3 – caw Nov 27 '12 at 17:23
  • I assume you tried without FLAG_DITHER, too. Do you have to use Eclipse for the screen capture? How about just using one of the myriad screen capture tools available, one that allows you to capture just the part of the screen that you want (by drawing a rectangle)? – hBrent Nov 28 '12 at 20:49
  • Yes, tried without FLAG_DITHER too, of course. I have to use Eclipse (at least I think so), because I'm running the app in the emulator. I need screenshots in size 800x480 and my personal device is smaller. Furthermore, I was assuming it's not Eclipse's fault but my app's fault, so I have to change something to make the drawables work correctly. – caw Nov 28 '12 at 22:11
  • The screen capture programs I was referring to are desktop applications, not phone apps, so that you can get screenshots of the emulator. An example is ScreenHunter, though there are many others, and OS X has its own built-in tools. I'm not sure that the problem is your app, if everything looks OK to your eye. You may want to try using Eclipse to take some screenshots of other apps (e.g., one or more of the sample apps that come with the Android SDK) and see how those look. – hBrent Nov 28 '12 at 22:30
  • So far, I've never been experiencing this issue in the emulator, even not with gradient drawables. But so far, I haven't been using an emulator with such a high resolution, either. Maybe this is the cause. Or maybe I just didn't set up the emulator correctly. What I can say, however, is that when I capture the screen on Windows, the resulting screenshot is not as large as needed. So it's smaller on Windows than its actual resolution. – caw Nov 28 '12 at 22:50
  • I would recommend seeing how one or more of the sample apps look. Several use gradients like yours. (I just searched for " – hBrent Nov 28 '12 at 23:01
  • Updated to Eclipse 3.8 and Android SDK Tools 21, by the way, and no change. – caw Nov 29 '12 at 01:53
  • I just noticed that in the emulator itself, not the screenshot, there are these lines showing low quality as well. But they are not as easy to notice as in the screenshot. So maybe it's a code problem instead of an Eclipse problem ... – caw Nov 29 '12 at 02:47
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20345/discussion-between-hbrent-and-marco-w) – hBrent Nov 29 '12 at 17:05
  • 3
    I don't think that it's your app. I tried this in my emulator as well. I tried screenshotting the home screen (not in any app) and the background has all sorts of gradients. It was low quality there as well. – davehale23 Nov 29 '12 at 17:14
  • Try setting your color values to 8-digit values to include alpha e.g FFFFFFFF and FFCCCCCC instead of FFFFFF and CCCCCC. – Gunnar Karlsson Dec 01 '12 at 10:13
  • @davehale23 I've checked that on a real device (tablet): It is not the app but the emulator or Eclipse, you were right. – caw Dec 01 '12 at 12:30
  • So you could use DDMS and take a screenshot of your app... – Snicolas Dec 01 '12 at 15:38
  • I think using Eclipse is equivalent to the DDMS, so no effect. http://stackoverflow.com/questions/2065993/how-to-take-emulator-screen-shots-using-eclipse – caw Dec 01 '12 at 17:03
  • I think @Snicolas meant use DDMS to take a screenshot from your tablet. – hBrent Dec 01 '12 at 19:53
  • Ah, okay, sorry. But then I can just as well use Eclipse to take the screenshot from my tablet, as the problem seems to be the emulator, right? – caw Dec 01 '12 at 20:16
  • I think so. Why don't you try ? From eclipse, you can use ddms to take a screenshot – Snicolas Dec 01 '12 at 21:01
  • I recommend user 3rd party software. – wtsang02 Dec 01 '12 at 21:09
  • 2
    Graphics on the emulator are very time consuming; therefore it is likely that the higher resolution emulator instances use a fairly limited bit depth (coarse color choices) to keep things from being even more painfully slow than they already are. Also the DDMS screenshot code might not be capturing the actual bit depth used. You may need to hunt down a physical device of sufficient resolution, or simulate the screenshot somehow. – Chris Stratton Dec 01 '12 at 22:02
  • Have you tried taking the screen shot in code? Example: http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android – logray Dec 02 '12 at 06:39
  • screenshot is also depends on the emulators resolution as well, I have never encountered such case, try to create emulator with high resolution – Nixit Patel Dec 03 '12 at 07:06
  • 1
    This emulator had high (enough) resolution, namely 800x480. Same as real device, but screenshot was poor quality. Conclusion: Screenshots should be taken from real devices, as the emulator has often limited bit depth. Thank you all! – caw Dec 03 '12 at 14:38

4 Answers4

8

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.

caw
  • 30,999
  • 61
  • 181
  • 291
5

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.

DK2
  • 502
  • 7
  • 5
1

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>
logray
  • 2,332
  • 1
  • 29
  • 30
0

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/

gaborsch
  • 15,408
  • 6
  • 37
  • 48
Rolz73
  • 1