Living environment of a table gradient: is it possible to use ARGB_8888 or anti-aliasing?

I create Live Wallpaper, and I draw on the canvas on each Runnable.run () with a changing color, and I hope the gradient is on top, but the gradient I create is a terrible binding. After several attempts by Google for several days, I came up with 2 solutions: set the anti-aliasing value to true; set the canvas bitmap to ARGB_8888

I tried to make the first one (set dither to true) on getWallpaper () and the Paint object, but that didn't help (I don't see any anti-aliasing at all), so I tried changing the canvas bitmap, but I'm not sure how to display it

// _canvasBmp = Bitmap.createBitmap(metrics.widthPixels, metrics.heightPixels, Bitmap.Config.ARGB_8888);

_shadowPaint.setStyle(Paint.Style.FILL);
_shadowPaint.setShader(new RadialGradient(metrics.widthPixels / 2,
metrics.heightPixels / 2, metrics.heightPixels / 2, 0x00000000,0x33000000, Shader.TileMode.CLAMP));
_shadowPaint.setDither(true); // this hasn't seemed to have done anything to fix the banding

// my main rendering method is this (based on the Google live wallpaper example)
void drawFrame()
{
   final SurfaceHolder holder = getSurfaceHolder();

   Canvas c = null;
   try
   {
           c = holder.lockCanvas();
           // c.setBitmap(_canvasBmp);// this was my attempt to update the bitmap to one that was ARGB_8888 but it didn't render at all

           if (c != null)
           {
                   // draw something
                   drawBackground(c);
                   drawTouchPoint(c);
                   drawShading(c);
                   drawBorder(c);

                   getWallpaper().setDither(true); // yet another attempt to get some kind of dithering going to no avail
           }
   }
   finally
   {
           if (c != null)
                   holder.unlockCanvasAndPost(c);
   }

   _handler.removeCallbacks(_drawClock); // _drawClock is the Runnable object

   if (_isVisible)
   {
           _handler.postDelayed(_drawClock, 1000 / 25);
   }
}


private void drawShading(Canvas c)
{
    c.drawRect(_screenBounds, _shadowPaint); // _screenBounds is a Rect set to the _metrics width and height
}

Thank you in advance for your time.

+3
source share
1 answer

PinupEngine...

@Override
public void onCreate(SurfaceHolder surfaceHolder) {
  super.onCreate(surfaceHolder);
  surfaceHolder.setFormat(android.graphics.PixelFormat.RGBA_8888);
}

, LiveWallpaper . , ( ). , , RGBA_8888, . RGB_565 , .

+4

Source: https://habr.com/ru/post/1792196/


All Articles