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

发布于 2024-10-17 08:33:37 字数 1802 浏览 2 评论 0原文

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

我尝试在 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
}

提前感谢您的时间

I am creating a Live Wallpaper and I'm painting to the canvas on every
Runnable.run() call with a changing colour and i'm hoping to put a
gradient over the top but the gradient i'm creating is banding
horribly. After Googling around for a few days I came up with 2 solutions:
set the dither to true
set the canvas bitmap to ARGB_8888

i've tried doing the first one (set dither to true) on the
getWallpaper() accessor and the Paint object but it's not helped (I can't see
any dithering at all) so I've tried changing the canvas bitmap but i'm
not sure how to actually display it

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

Thanks in advance for your time

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-10-24 08:33:37

在您的 PinupEngine 类中...

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

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

In your PinupEngine class...

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

I have found that the LiveWallpaper drawing is slower with the larger bitmap pixel type. I expect it will also use a lot more memory (More than Double). If you can it might pay to try and limit the use of RGBA_8888 if possible. Default is RGB_565 I think, not sure about that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文