从Java移植到Android - BufferedImage

时间:2013-07-02 14:10:46

标签: java android bitmap sprite bufferedimage


我有一个Java小程序,我正在加载和动画Sprites函数看起来像这样:

public void addSprite(BufferedImage image, long duration,
        int rows, int cols, int width, int height) {
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            long durationFrame = (long) (duration / (cols * rows));
            addFrame(image.getSubimage(j * width, i * height,
                    width, height), durationFrame);
        }
    }
}

addFrame方法将子图像保存到ArrayList中,并显示图像的持续时间。

一切正常,但很明显 BufferedImage 不是Android软件包的一部分,因此我必须使用Bitmap修改方法。
但我有问题用类似的东西交换 getSubimage 方法,我认为Bitmap类的 getPixels(...)方法应该这样做,但我不知道我知道如何正确使用它来获得相同的结果,因为参数是完全不同的,有人可以给我一个提示,我可以如何交换它:

image.getSubimage(x, y, width, height)

这个(假设getPixels()方法是正确的选择):

image.getPixels(pixels, offset, stride, x, y, width, height)


已经感谢您的支持

0 个答案:

没有答案