Android - 在自定义视图中滚动位图
我有一个尺寸为 400 x 70 像素的位图。我想将此位图向上滚动一行并用新像素填充第 70 行。 我尝试通过将位图复制到 IntBuffer 来滚动位图,将其复制到另一个 IntBuffer (从第二行开始),然后将其写回位图。 这可行,但需要大量的 CPU 能力,而且速度有点慢。 有没有更快的方法来做到这一点?
private Bitmap shift(Bitmap bitmap)
{
buffer.rewind();
buffer1.rewind();
bitmap.copyPixelsToBuffer(buffer);
buffer.position(bitmap.getWidth());
buffer1.put(buffer.array(), bitmap.getWidth()*2, bitmap.getWidth() * bitmap.getHeight());
buffer1.rewind();
bitmap.copyPixelsFromBuffer(buffer1);
return bitmap;
}
I have a bitmap with the size of 400 x 70 pixels. I would like to scroll this bitmap up by one row and fill up row 70 with new pixels.
I have tried to scroll the bitmap by copying it to an IntBuffer , copy it to another IntBuffer (starting at the second row) and the then write it back to the bitmap.
This works but it takes a lot of CPU power and it is kind of slow.
Is there any faster way to do this?
private Bitmap shift(Bitmap bitmap)
{
buffer.rewind();
buffer1.rewind();
bitmap.copyPixelsToBuffer(buffer);
buffer.position(bitmap.getWidth());
buffer1.put(buffer.array(), bitmap.getWidth()*2, bitmap.getWidth() * bitmap.getHeight());
buffer1.rewind();
bitmap.copyPixelsFromBuffer(buffer1);
return bitmap;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是使用画布实现此目的的一种方法:
bgrDx 是滚动速度(尝试 bgrDx = 1),而 bgrW 是 bgr 位图的宽度。
此方法重复图像并产生无限滚动,但是您需要使用循环图像(两端相同)以使滚动看起来无缝。也许您应该尝试一下,看看它是否对您有更好的效果。
This is one way to do it using canvas:
bgrDx is the speed of scrolling try bgrDx = 1, while bgrW is the width of the bgr bitmap.
This method repeats the image and produces an infinite scroll, however you would need to use a looped image (the same on both ends) to make the scroll look seamless. Perhaps you should experiment with this and see if it performs any better for you.