动态壁纸渐变带:是否可以使用 ARGB_8888 或抖动来修复?
我正在创建一个动态壁纸,并在每个画布上绘画 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 PinupEngine 类中...
我发现,位图像素类型越大,LiveWallpaper 绘制速度就越慢。我预计它也会使用更多的内存(超过双倍)。如果可以的话,尝试限制 RGBA_8888 的使用可能是值得的。我认为默认值是 RGB_565,对此不确定。
In your PinupEngine class...
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.