Here you can find the source of image2Bytes(File f)
public static byte[] image2Bytes(File f) throws Exception
//package com.java2s; //License from project: Apache License import javax.imageio.ImageIO; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; import java.io.File; public class Main { public static byte[] image2Bytes(File f) throws Exception { BufferedImage bi = ImageIO.read(f); int imageType = bi.getType(); int width = bi.getWidth(); int height = bi.getHeight(); BufferedImage grayImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null).filter(bi, grayImage); return (byte[]) grayImage.getData().getDataElements(0, 0, width, height, null); }/*from w ww . j ava 2 s . c om*/ }