Convert pixels from java default ARGB int format to byte array in ABGR format. - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

Convert pixels from java default ARGB int format to byte array in ABGR format.

Demo Code

/*/* w w  w . java2 s. com*/
 * Image conversion utilities.
 * 
 * Copyright (c) 2006 Jean-Sebastien Senecal (js@drone.ws)
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
 * Ave, Cambridge, MA 02139, USA.
 */
//package com.java2s;

public class Main {
    /**
     * Convert pixels from java default ARGB int format to byte array in ABGR
     * format.
     * 
     * @param pixels the pixels to convert
     */
    public static void convertARGBtoABGR(int[] pixels) {
        int p, r, g, b, a;
        for (int i = 0; i < pixels.length; i++) {
            p = pixels[i];
            a = (p >> 24) & 0xFF; // get pixel bytes in ARGB order
            r = (p >> 16) & 0xFF;
            g = (p >> 8) & 0xFF;
            b = (p >> 0) & 0xFF;
            pixels[i] = (a << 24) | (b << 16) | (g << 8) | (r << 0);
        }
    }
}

Related Tutorials