android - 动态壁纸渐变条纹 : is it possible to use ARGB_8888 or dithering to fix?

标签 android gradient live-wallpaper

我正在创建一个动态壁纸,我正在 Canvas 上的每一个 Runnable.run() 调用颜色不断变化,我希望放一个 渐变在顶部,但我正在创建的渐变是带状的 可怕的。谷歌搜索了几天后,我想出了两个解决方案: 将抖动设置为真 将 Canvas 位图设置为 ARGB_8888

我试过在 getWallpaper() 访问器和 Paint 对象,但它没有帮助(我看不到 任何抖动)所以我尝试更改 Canvas 位图但我 不确定如何实际显示它

// _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
}

提前感谢您的宝贵时间

最佳答案

在你的 PinupEngine 类中......

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

我发现使用较大的位图像素类型,LiveWallpaper 绘图速度较慢。我预计它也会使用更多的内存(超过两倍)。如果可以的话,尝试限制 RGBA_8888 的使用可能是值得的。我认为默认是 RGB_565,对此我不确定。

关于android - 动态壁纸渐变条纹 : is it possible to use ARGB_8888 or dithering to fix?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5002586/

相关文章:

Android Firebase 如何获取父节点的所有子节点值?

android - 增加 clipPath 大小会导致滞后

android - 当点击相机时,Android Live Wallpaper崩溃

android - 使用动画 gif 的动态壁纸(使用 centercrop scaletype)

Android Geocoder 无法在 Nexus 6P 和 Android Nougat 7.0 中运行

android - 无法生成签名的 apk,但工作正常

java - 使用正则表达式验证 EditText 中的 [Preference] 文件名

iphone - 设置一次后如何去除UIButton的渐变效果 - iPhone

swift - 如何使单元格具有渐变背景?

Javascript 颜色渐变