Blackberry: how to flip a Bitmap upside down? -


how flip bitmap upside down?

(i need loading opengl texture in program).

here failed try:

screenshot

stripe.png (courtesy of pitr@openclipart):

enter image description here

flip.java:

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 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());         (int = 0; < bitmap.getheight(); i++) {             (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;     } } 

try using bit of code:

    (int y = 0; y < bitmap.getheight() / 2; y++) {         int upper_row = bitmap.getwidth() * y;         int lower_row = bitmap.getwidth() * (bitmap.getheight() - 1 - y);         (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;         }     } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -