Here you can find the source of getBytesPerPixel(int bufferedImageType)
Parameter | Description |
---|---|
imageType | as used for BufferedImage#BufferedImage(int,int,int) |
public static int getBytesPerPixel(int bufferedImageType)
//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; } }