当转换用于绘制位图的矩阵时,它会绘制多个位图

发布于 2024-11-25 21:24:14 字数 559 浏览 5 评论 0原文

在我的 Android 项目中,我有一个矩阵,用于在画布上绘制位图。在我的drawFrame方法中,我在Y方向上平移矩阵,这样看起来位图正在向上移动。它确实向上移动,但也被绘制在之前的位置,留下了多个自身。这是我的drawFrame代码:

Canvas canvas = null;
canvas = holder.lockCanvas();

Matrix moveMatrix = new Matrix ();
moveMatrix.postTranslate(0, 10);
matrix.preConcat(moveMatrix);

canvas.drawBitmap(bitmap, matrix, null);

holder.unlockCanvasAndPost(canvas);

“matrix”是全局Matrix成员。

有谁知道为什么这会在屏幕上留下位图的“条纹”痕迹?

谢谢!

我忘了提到,每次位图移动时,之前的每个位图位置似乎都会在 y 方向上上下移动。所以它最终会得到一串位图,看起来像是在上下抖动。这意味着每帧都必须重新绘制每个位图,否则它们都会静止不动。

In my Android project, I have a matrix that I use to draw a bitmap on a canvas. During my drawFrame method, I translate the matrix in the Y direction so it looks like the bitmap is moving up. It does move up, but it is also drawn in the previous position leaving multiples of itself behind. Here is my drawFrame code:

Canvas canvas = null;
canvas = holder.lockCanvas();

Matrix moveMatrix = new Matrix ();
moveMatrix.postTranslate(0, 10);
matrix.preConcat(moveMatrix);

canvas.drawBitmap(bitmap, matrix, null);

holder.unlockCanvasAndPost(canvas);

"matrix" is a global Matrix member.

Does anyone know why this leaves a "streaking" trail of bitmaps across the screen?

Thanks!

I forgot to mention that each previous bitmap position seems to shift up and down in the y direction every time the bitmap moves. So it ends up with a string of bitmaps that look like they are jittering up and down. This would mean that every bitmap would have to be redrawn every frame otherwise they would all be standing still.

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

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

发布评论

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

评论(1

你好,陌生人 2024-12-02 21:24:14

您需要清除位图先前位置的画布:)

You need to clear the Canvas at the previous position of the bitmap :)

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