Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GIf图像在android中转换为Base64,无需使用压缩_Android - Fatal编程技术网

GIf图像在android中转换为Base64,无需使用压缩

GIf图像在android中转换为Base64,无需使用压缩,android,Android,我的代码是,在这段代码中,所有图像都转换为base 64,但在gif图像中,也在png中,我希望转换后成为gif ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByt

我的代码是,在这段代码中,所有图像都转换为base 64,但在gif图像中,也在png中,我希望转换后成为gif

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
return Base64.encodeToString(byteArray, Base64.NO_WRAP);

=>此代码正在成功运行

 byte[] inputData = getBytes(iStream);

 Base64.encodeToString(inputData, Base64.NO_WRAP)

 public byte[] getBytes(InputStream inputStream) throws IOException {
    ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
    int bufferSize = 1024;
    byte[] buffer = new byte[bufferSize];

    int len = 0;
    while ((len = inputStream.read(buffer)) != -1) {
        byteBuffer.write(buffer, 0, len);
    }
    return byteBuffer.toByteArray();
}

public static String encodeToString(byte[] input, int flags) {
    try {
        return new String(encode(input, flags), "US-ASCII");
    } catch (UnsupportedEncodingException e) {
        // US-ASCII is guaranteed to be available.
        throw new AssertionError(e);
    }
}