.bmpファイルのピクセル値を含むバイト配列があります。これを行うことによって生成されました:
BufferedImage readImage = ImageIO.read(new File(fileName));
byte imageData[] = ((DataBufferByte)readImage.getData().getDataBuffer()).getData();
次に、.bmpイメージを再作成する必要があります。このメソッドを呼び出して、BufferedImageを作成し、WritableRasterのピクセルを設定しようとしましたsetPixels
。ただし、int []、float []、またはdouble[]配列を指定する必要があります。たぶん私はバイト配列をこれらの1つに変換する必要があります。しかし、私はそれを行う方法がわかりません。私もその方法を試しましたsetDataElements
。しかし、この方法の使い方もわかりません。
バイト配列からbmpイメージを作成する方法を誰かが説明できますか?
編集: @Perception
これは私がこれまでに行ったことです:
private byte [] getPixelArrayToBmpByteArray(byte [] pixelData、int width、int height、int depth)throws Exception {int [] pixel = byteToInt(pixelData); BufferedImage image = null; if(depth == 8){image = new BufferedImage(width、height、BufferedImage.TYPE_BYTE_GRAY); } else if(depth == 24){image = new BufferedImage(width、height、BufferedImage.TYPE_INT_RGB); } WritableRasterラスター=(WritableRaster)image.getData(); ラスター.setPixels(0、0、幅、高さ、ピクセル); image.setData(raster); getBufferedImageToBmpByteArray(image);を返します。} private byte [] getBufferedImageToBmpByteArray(BufferedImage image){byte [] imageData = null; {ByteArrayOutputStream bas = new ByteArrayOutputStream();を試してください。ImageIO.write(image、 "bmp"、bas); imageData = bas.toByteArray(); bas.close(); } catch(例外e){e.printStackTrace(); } return imageData; } private int [] byteToInt(byte [] data){int [] ints = new int [data.length]; for(int i = 0; i