如何将较小的位图复制到较大的位图?

发布于 2024-08-23 05:01:39 字数 205 浏览 4 评论 0原文

希望这应该是一个简单的问题。我正在尝试将一系列小位图复制到较大的位图中,将它们并排排列,像素中没有任何间隙或重叠。例如,如果我有 3 个正方形位图,我想将它们复制到一个细长的矩形中。我知道如何做相反的事情,即从较大的位图创建一个小位图,但不是这样。正确的命令是什么?

(如果有人好奇,我希望这样做是为了能够重用我为使用单个位图处理动画而编写的一些代码。)

谢谢!

Hopefully this should be an easy question. I'm trying to copy a series of small bitmaps into a larger one, arranging them side by side without any gaps or overlap in their pixels. For example, if I have 3 square bitmaps, I'd like to copy them into one long and thin rectangle. I know how to do the opposite, namely creating a small bitmap out of a larger one, but not this way around. What's the right command?

(If anyone's curious, I want to do this to be able to reuse some code I wrote for handling animation with a single bitmap.)

Thanks!

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

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

发布评论

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

评论(1

说谎友 2024-08-30 05:01:39

为大位图创建画布,然后用它来绘制小位图。我对android很陌生,但我猜它是这样的:

Bitmap makeBigBitmap(Bitmap srcBmps[]) {
    Bitmap wideBmp;
    Canvas wideBmpCanvas;
    Rect src, dest;

    // assume all of the src bitmaps are the same height & width
    wideBmp = Bitmap.createBitmap(srcBmps[0].getWidth() * srcBmps.length, 
        srcBmps[0].getHeight(), srcBitmaps[0].getConfig());

    wideBmpCanvas = new Canvas(wideBmp); 

    for (int i = 0; i < srcBmps.length; i++) {
         src = new Rect(0, 0, srcBmps[i].getWidth(), srcBmps[i].getHeight());
         dest = new Rect(src); 
         dest.offset(i * srcBmps[i].getWidth(), 0); 

         wideBmpCanvas.drawBitmap(srcBmps[i], src, dest, null); 
    }

    return wideBmp;
}

Create a canvas for the large bitmap, then use that to draw your small bitmaps. I'm pretty new to android, but I'm guessing that it's something like this:

Bitmap makeBigBitmap(Bitmap srcBmps[]) {
    Bitmap wideBmp;
    Canvas wideBmpCanvas;
    Rect src, dest;

    // assume all of the src bitmaps are the same height & width
    wideBmp = Bitmap.createBitmap(srcBmps[0].getWidth() * srcBmps.length, 
        srcBmps[0].getHeight(), srcBitmaps[0].getConfig());

    wideBmpCanvas = new Canvas(wideBmp); 

    for (int i = 0; i < srcBmps.length; i++) {
         src = new Rect(0, 0, srcBmps[i].getWidth(), srcBmps[i].getHeight());
         dest = new Rect(src); 
         dest.offset(i * srcBmps[i].getWidth(), 0); 

         wideBmpCanvas.drawBitmap(srcBmps[i], src, dest, null); 
    }

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