Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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>

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/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top