动态壁纸渐变条纹:是否可以使用ARGB_8888或抖动修复?

时间:2011-02-15 10:37:46

标签: android gradient live-wallpaper

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

我已经尝试过第一个(将dither设为true) getWallpaper()访问器和Paint对象,但它没有帮助(我看不到 任何抖动都是如此)所以我试过改变画布位图,但我是 不知道如何实际显示它

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

提前感谢您的时间

1 个答案:

答案 0 :(得分:4)

在你的PinupEngine课程......

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

我发现使用较大的位图像素类型时LiveWallpaper绘图较慢。我希望它也会使用更多的内存(超过双倍)。如果可以的话,如果可能的话,尝试限制使用RGBA_8888可能会付出代价。默认是RGB_565我想,不确定。