2011-02-15 30 views
3

我正在创建一个动态壁纸,我正在绘画到每一个 Runnable.run()调用不断变化的颜色,我希望在顶部放一个 渐变,但是我创建的渐变是可怕地绑带 。周围的Googling几天后,我想出了2个解决方案: 设置抖动为true 设置画布位图ARGB_8888动态壁纸渐变色带:是否可以使用ARGB_8888或抖动来修复?

我试着做的 getWallpaper第一个(组抖动为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 
} 

预先感谢您的时间

回答

4

在你PinupEngine类...

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

我发现,LiveWallpaper图是具有较大的位图像素类型慢。我预计它也会使用更多的内存(超过双倍)。如果可以的话,可能会付出努力尝试限制RGBA_8888的使用。默认是RGB_565我认为,不确定。

+0

这太棒了 - 非常感谢 – obie 2011-02-23 14:41:03