我正在创建一个动态壁纸,并且我在每次 Runnable.run() 调用时用不断变化的颜色在画布上绘画,我希望在顶部放置一个渐变,但我正在创建的渐变是可怕的带状。在谷歌搜索了几天后,我想出了 2 个解决方案:将抖动设置为 true 将画布位图设置为 ARGB_8888
我已经尝试在 getWallpaper() 访问器和 Paint 对象上执行第一个(将抖动设置为 true)但它没有帮助(我根本看不到任何抖动)所以我尝试更改画布位图但我'不知道如何实际显示它
// _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
}
在此先感谢您的时间