小编vin*_*nag的帖子

将 ImageOutputStream 转换为 byte[]

一直在尝试使用 JAI 将 ImageOutputStream 转换为 byte[] 一段时间。任何输入表示赞赏。谢谢。

抱歉,这是代码片段,我正在处理。我不得不提前发布它。我面临的问题是,我能够从 ImageOutputStream 获取 ByteArrayOutputStream。但它总是给我零字节。但是如果我使用 FileOutputStream 而不是 ByteArrayOuputStream,我可以写入一个非零字节的文件。:

File file = new File("C:/TIFFImages/tiff-image.tiff");
FileInputStream in = new FileInputStream(file);
long filelength = file.length();
byte[] bytes = new byte[(int)filelength]; 
int offset = 0; 
int numRead = 0; 

while (offset < bytes.length && (numRead=in.read(bytes, offset, bytes.length-offset)) >= 0) { 
    offset += numRead; 
} 
if (offset < bytes.length) { 
    throw new IOException("Could not completely read file "+file.getName()); 
} 

ByteArrayInputStream bais = new ByteArrayInputStream(bytes);

RenderedImage src = JAI.create("stream", SeekableStream.wrapInputStream(bais, …
Run Code Online (Sandbox Code Playgroud)

java image jai

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

image ×1

jai ×1

java ×1