2011-05-10 44 views
1

Hy。我要水平翻轉圖像,我用這個代碼:如何翻轉EncodedImage黑莓

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; 

} 

Buut ..沒有人有一個IDEEA如何直接EncodedImage翻轉無需轉換,因爲它採取長期

附:一點點PNGEncoder.java在這裏:http://www.mobiyana.com/code/blackberry/PNGEncoder.java

回答

0

Graphics.drawTexturedPath()可以爲你做我想做的事情。看看這個來自RIM的javadoc

+0

是的,但我做了一個遊戲,首先我需要加載翻轉的圖片並在遊戲中畫出 – AndreiCatalin 2011-05-10 10:51:44

+0

不明白!你能更清楚嗎? – 2011-05-10 11:45:51

1

有效的解決方案是提供兩個版本的圖像;一個正常,一個翻轉。當然,您必須考慮加載所花費的時間量與圖片所需的空間量。如果你正在尋找更快的加載時間,這是一個至少應該考慮的設計決定。

+0

我受空間限制(只有5mb)我無法添加到許多圖片。無論如何感謝您的介入。 – AndreiCatalin 2011-05-10 13:20:08