问题描述
输入是黑白图像。需要使用 group 函数对其进行压缩以对图像进行编码。相反,我的尺寸反而增加了。感谢您提供的任何帮助:)
public static void main(String[] args) throws IOException {
File rleImage=new File("pool.png");
BufferedImage img=ImageIO.read(rleImage);
byteArray(img);
getRunLength();
try{
File newImage = new File("Saved.png");
ImageIO.write(img,"BMP",newImage);
}catch(Exception e){
System.out.println("Error");
}
}
public static byte[] byteArray(BufferedImage image){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] imageInByte = null;
try{
ImageIO.write(image,baos);
baos.flush();
imageInByte = baos.toByteArray();
baos.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
return imageInByte;
}
public static byte[] getRunLength(){
ByteArrayOutputStream dest = new ByteArrayOutputStream();
byte lastByte = imageByteArray[0];
int matchCount = 1;
for(int i=1; i < imageByteArray.length; i++){
byte thisByte = imageByteArray[i];
if (lastByte == thisByte) {
matchCount++;
}
else {
dest.write((byte)matchCount);
dest.write((byte)lastByte);
matchCount=1;
lastByte = thisByte;
}
}
dest.write((byte)matchCount);
dest.write((byte)lastByte);
return dest.toByteArray();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)