我们正在使用java进行图像压缩解压缩项目。我们已经使用base64编码器编码了图像,而不是在代码下面应用。但是这个java代码不能用于图像。它适用于char字符串,但不适用于图像。
StringBuffer dest = new StringBuffer();
for (int i = 0; i < source.length(); i++)
{
int runLength = 1;
while (i + 1 < source.length() && source.charAt(i) == source.charAt(i + 1))
{
runLength++;
i++;
}
dest.append(runLength);
dest.append(source.charAt(i));
}
return dest.toString();
答案 0 :(得分:0)
答案 1 :(得分:0)
public byte[] byteArray(BufferedImage image){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] imageInByte = null;
try{
ImageIO.write(image, "BMP", baos);
baos.flush();
imageInByte = baos.toByteArray();
baos.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
return imageInByte;
}
public String getRunLength(){
StringBuffer dest = new StringBuffer();
for(int i =0; i < imageByteArray.length; i++){
int runlength = 1;
while(i+1 < imageByteArray.length && imageByteArray[i] == imageByteArray[i+1]){
runlength++;
i++;
}
dest.append(runlength);
dest.append(imageByteArray[i]);
}
return dest.toString();
}