i have an array of type byte.that array consist of the bytes read from an bmp image file.now how to recreate a bmp image file through that byte array.i have heared that it can be created by using bufferedimage and some other class.provide me the code of recreating the image through an array of byte using bufferedimage class.
byte rasterdata=new byte[br.available()]; //this is the array which has the byte of a bmp image.
ByteArrayInputStream bis= new ByteArrayInputStream(rasterdata);
Iterator<?> readers = ImageIO.getImageReadersByFormatName("bmp");
ImageReader reader = (ImageReader) readers.next();
Object source = bis;
ImageInputStream iis = ImageIO.createImageInputStream(source);
ImageReadParam param = reader.getDefaultReadParam();
Image image = reader.read(0,param); //and this the place where i am getting the following error
Exception in thread "main" java.lang.IllegalArgumentException: Invalid magic value for BMP file.
at com.sun.imageio.plugins.bmp.BMPImageReader.readHeader(Unknown Source)
at com.sun.imageio.plugins.bmp.BMPImageReader.read(Unknown Source)
all i can tell you for sure is ImageIO can read the .bmp i just created in microsoft Paint. your code seems kind of complicated to me. mine seems much simpler.
where image is a BufferedImage.
don't know if that helps
i give up. i copy code and use code tags. it looks fine when i paste it, but when it posts it is screwed up. even now as i edit, the code is indented properly. but once i post, it will be screwed up.
any image can be read through FileInputSteram and the data can be stored in an array of byte.every image contains the header,other information and the image data of its specific type.suppose if we have read the header and after a specific offset in the byte stream ,the image data starts.that image data can be used in drawing images through JFrame.
There is a way to draw that image from that image data without those headers information.it can be done by taking the image data in some DataBufferInt and some of the methods i remember are getRaster().getDataBuffer().with the help of these the image can be generated in a JFrame.
so can you provide me the code to do this task.
@Randall Twede:i want the code to read the data of an image in byte form and then recreate that image with the help of that byte data excluding the header information.