Blackberry: how to flip a Bitmap upside down? -
how flip bitmap upside down?
(i need loading opengl texture in program).
here failed try:
stripe.png (courtesy of pitr@openclipart):
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
Post a Comment