Java BufferedImage to Byte Array getBytesPerPixel(int bufferedImageType)

Here you can find the source of getBytesPerPixel(int bufferedImageType)

Description

get Bytes Per Pixel

License

Open Source License

Parameter

Parameter Description
imageType as used for BufferedImage#BufferedImage(int,int,int)

Declaration

public static int getBytesPerPixel(int bufferedImageType) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) OSMCB developers/*from   w  w w  . ja v a2  s  . c om*/
 * 
 * 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, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.awt.image.BufferedImage;

public class Main {
    /**
     * 
     * @param imageType
     *          as used for {@link BufferedImage#BufferedImage(int, int, int)}
     * @return
     */
    public static int getBytesPerPixel(int bufferedImageType) {
        switch (bufferedImageType) {
        case BufferedImage.TYPE_INT_ARGB:
        case BufferedImage.TYPE_INT_ARGB_PRE:
        case BufferedImage.TYPE_INT_BGR:
        case BufferedImage.TYPE_4BYTE_ABGR:
        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            return 4;
        case BufferedImage.TYPE_3BYTE_BGR:
            return 3;
        case BufferedImage.TYPE_USHORT_GRAY:
        case BufferedImage.TYPE_USHORT_565_RGB:
        case BufferedImage.TYPE_USHORT_555_RGB:
            return 2;
        case BufferedImage.TYPE_BYTE_GRAY:
        case BufferedImage.TYPE_BYTE_BINARY:
        case BufferedImage.TYPE_BYTE_INDEXED:
            return 1;
        }
        return -1;
    }
}

Related

  1. getByteImage(BufferedImage imagem)
  2. getBytes(BufferedImage image)
  3. getBytes(final InputStream is, final int bufferSize)
  4. getBytesFromBufferedImage(BufferedImage bi, String format)
  5. getBytesFromImage(String fileIn, String fileOut)
  6. image2Bytes(BufferedImage image)
  7. image2Bytes(File f)
  8. imageToByte(BufferedImage bi, String format)
  9. imageToByte(BufferedImage image)