1

海。我想水平翻转图像并使用以下代码:

public static EncodedImage flip (Bitmap png)
{
    int width = png.getWidth();
    int height = png.getHeight();
    Bitmap temp = new Bitmap(width,height);
    int[] argb = new int[ width * height ];
    int[] invertArgb = new int[ width * height ];
    png.getARGB( argb, 0, width, 0, 0, width, height );

    for ( int i = height - 1; i >= 0; --i ) {
        for ( int j = width - 1; j >= 0; --j ) {
            invertArgb[ ( width - j - 1 ) + ( width * i ) ] = argb[ j + ( width * i ) ];
        }
    }
    temp.setARGB( invertArgb, 0, width, 0, 0, width, height );

    PNGEncoder encoder = new PNGEncoder(temp, true);
    byte[] imageBytes = null;
    try {
        imageBytes = encoder.encode(true);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    EncodedImage fullImage = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);

    return fullImage;

}

但是..有没有人知道如何在EncodedImage不转换的情况下直接翻转,因为它需要一点时间

PS PNGEncoder.java 在这里:http ://www.mobiyana.com/code/blackberry/PNGEncoder.java

4

2 回答 2

1

一个有效的解决方案是提供两个版本的图像;一个正常,一个翻转。当然,您必须考虑加载所需的时间与图像所需的空间量。如果您正在寻找更快的加载时间,那么至少应该考虑这个设计决策。

于 2011-05-10T12:56:22.193 回答
0

我想 Graphics.drawTexturedPath() 可以为你做事。看看RIM的这个javadoc

于 2011-05-10T07:46:10.927 回答