2011-07-02 3 views
2

Bitmap을 거꾸로 뒤집는 방법은 무엇입니까?Blackberry : Bitmap을 거꾸로 뒤집는 방법은 무엇입니까?

(다른 프로그램에서 OpenGL 텍스처를로드 할 때 필요합니다).

import net.rim.device.api.system.*; 
import net.rim.device.api.ui.*; 
import net.rim.device.api.ui.component.*; 
import net.rim.device.api.ui.container.*; 

public class Flip extends UiApplication { 
    public static void main(String args[]) { 
     Flip app = new Flip(); 
     app.enterEventDispatcher(); 
    } 

    public Flip() { 
     pushScreen(new MyScreen()); 
    } 
} 

class MyScreen extends MainScreen { 
    static final Bitmap STRIPE = flip(Bitmap.getBitmapResource("stripe.png")); 

    public MyScreen() { 
     setTitle("Flip the bitmap"); 
     add(new BitmapField(STRIPE)); 
     add(new ButtonField("Hello world")); 
    } 

    static Bitmap flip(Bitmap bitmap) { 
     int[] argb = new int[bitmap.getWidth() * bitmap.getHeight()]; 
     bitmap.getARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); 
     for (int i = 0; i < bitmap.getHeight(); i++) { 
      for (int j = 0; j < bitmap.getWidth(); j++) { 
       int swap = argb[i * bitmap.getWidth() + j]; 
       argb[(bitmap.getHeight() - 1 - i) * bitmap.getWidth() + j] = swap; 
      } 
     } 
     bitmap.setARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); 
     return bitmap; 
    } 
} 

답변

3

하여 사용해보십시오 :

screenshot

stripe.png ([email protected]의 제공) :

enter image description here

Flip.java 여기

내 실패 시도이다 공동의이 비트 드 :

for (int y = 0; y < bitmap.getHeight()/2; y++) { 
     int upper_row = bitmap.getWidth() * y; 
     int lower_row = bitmap.getWidth() * (bitmap.getHeight() - 1 - y); 
     for (int x = 0; x < bitmap.getWidth(); x++) { 
      int temp = argb[upper_row + x]; 
      argb[upper_row + x] = argb[lower_row + x]; 
      argb[lower_row + x] = temp; 
     } 
    } 
+0

작동, 고맙습니다! –

0
public Bitmap flip(Bitmap bitmap) { 

    int[] argb = new int[bitmap.getWidth() * bitmap.getHeight()]; 

    int[] argb_flip = new int[bitmap.getWidth() * bitmap.getHeight()]; 

    bitmap.getARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); 
    for (int i = 0; i < bitmap.getHeight(); i++) { 
     for (int j = 0; j < bitmap.getWidth(); j++) { 
      int swap = argb[i * bitmap.getWidth() + j]; 

      argb_flip[(bitmap.getHeight() - 1 - i) * bitmap.getWidth() + j] = swap; 
     } 
    } 

    bitmap.setARGB(argb_flip, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); 

    return bitmap; 
} 

반드시이 180도 이미지를 반전하는 데 도움이됩니다,이보십시오.

관련 문제