gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:38 25 4
gpt4 key购买 nike

我正在创建一个动态壁纸,我正在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com