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
_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);
void drawFrame()
{
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try
{
c = holder.lockCanvas();
if (c != null)
{
drawBackground(c);
drawTouchPoint(c);
drawShading(c);
drawBorder(c);
getWallpaper().setDither(true);
}
}
finally
{
if (c != null)
holder.unlockCanvasAndPost(c);
}
_handler.removeCallbacks(_drawClock);
if (_isVisible)
{
_handler.postDelayed(_drawClock, 1000 / 25);
}
}
private void drawShading(Canvas c)
{
c.drawRect(_screenBounds, _shadowPaint);
}
Thank you in advance for your time.
source
share