开发者

How to flip an EncodedImage Blackberry

Hy. I want to flip horizontal an image and I use this code:

public static EncodedImage flip (Bitmap png)
{
    int width = png.getWidth();
    int height = png.getHeight();
    Bitmap temp = new Bitmap(width,height);
    int[] argb = new int[ w开发者_如何学Pythonidth * 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;

}

Buut.. does anyone have an ideea how to flip directly EncodedImage without converting because it's taking a little bit long

P.S. PNGEncoder.java is here: http://www.mobiyana.com/code/blackberry/PNGEncoder.java


A valid solution is to provide two versions of the images; one normal and one flipped. Of course you will have to take into consideration the amount of time it takes to load versus the amount of space your images will require. It's a design decision that should at least be considered if you are looking for faster load times.


Graphics.drawTexturedPath() can do things for you I suppose. Take a look at this javadoc from RIM

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜