0

I'm trying to save a byte[] of raw image data to a .tiff file on my harddrive with the help of the Java Advanced Imaging API. There are some minor examples on the web but they didn't help me really because they don't match my exact problem.

I already managed to save the data from the byte[] to a .raw and can view the result with success so the source actually contains some data. The method in question is executable without any exceptions but all I get is a black image whenever I view it with the Windows XP ImageViewer.

This is my method:

public void saveTif(byte[] imgData) {
    BufferedImage bufferedImage = new BufferedImage( 1280, 1024, BufferedImage.TYPE_BYTE_GRAY );
    bufferedImage.createGraphics().drawBytes(imgData, 0, 1280*1024, 0, 0);

    TIFFEncodeParam params = new TIFFEncodeParam();
    params.setCompression( TIFFEncodeParam.COMPRESSION_NONE );
    String filenametiff = path + File.separatorChar + new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss'.tiff'").format(new Date());
    JAI.create("filestore", bufferedImage, filenametiff, "TIFF", params);
}
4

1 回答 1

1

Graphics.drawBytes()用于在图像上绘制文本(这不是很好,因为它使用 byte[],而不是 char[] 或 String,因此不支持字符集)。

Graphics.drawBytes()不能用于绘制原始像素。

要获得图像的正确表示,您应该BufferedImage从像素数据创建新图像,或者创建匹配图像并将数据设置在其上。看看RasterDataBuffer类。

于 2013-06-10T11:00:33.123 回答