Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, make sure that your original image looks good so you're not just getting the problem from there.<br> Then, in your onCreate() method, do:</p> <p><strong>code1:</strong></p> <pre><code>getWindow().getDecorView().getBackground().setDither(true); getWindow().setFormat(PixelFormat.RGBA_8888); </code></pre> <p><strong>Deprecated:</strong></p> <p><strike>getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);</strike></p> <p>And to load your image explicitly as a 32-bit image (RGBA-8888 configuration) add the following where you load your views:</p> <p><strong>code2:</strong></p> <pre><code>BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.gradient, options); findViewById(R.id.main).setBackgroundDrawable(new BitmapDrawable(gradient)); </code></pre> <p><br>Comparison between different approaches: (these are all screenshots from the resulting application)</p> <p>My source images (64 colors to the left, 24 bit to the right):<br> image1 and image2:<br> <img src="https://i.stack.imgur.com/EuFVB.png" alt="64-color"><img src="https://i.stack.imgur.com/xJER2.png" alt="24 bit"><br> 1: Raw <strong>64-color</strong> image (image1) set as background from layout XML:<br> <img src="https://i.stack.imgur.com/ChFoO.png" alt="Raw image"><br> 2: The same image (image1), using <strong>code1</strong>:<br> <img src="https://i.stack.imgur.com/zlkpU.png" alt="Dithered image"><br> 3: The same image (image1) using both <strong>code1</strong> and <strong>code2</strong>:<br> <img src="https://i.stack.imgur.com/sssjO.png" alt="explicit 32bit"><br> 4: image2, loaded with <strong>code1</strong> and <strong>code2</strong> (in this case the dithering is not really important as both the source and destination use 8 bits per color):<br> <img src="https://i.stack.imgur.com/2wazA.png" alt="higher original quality"><br><br></p> <p><em>Notice how the resulting artifacts in image 3 already exists in the original image.</em></p> <p>Note: if anyone knows how to shrink the images down a bit, feel free to edit this post... </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload