android - BitmapFactory.decodeByteArray 在 android 中返回 null

标签 android

在我的应用程序中,我将 base64 字符串转换为图像。为此,我最初将 base 64 文件转换为字节数组,后来尝试转换为图像。 要转换为图像,我使用以下代码

    File sdImageMainDirectory = new File("/data/data/com.ayansys.Base64trial");
    FileOutputStream fileOutputStream = null;
    String nameFile="Images";
    try {

        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize = 5;
        options.inDither = true; 
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);


        fileOutputStream = new FileOutputStream(
                sdImageMainDirectory.toString() +"/" + nameFile + ".jpg");


        BufferedOutputStream bos = new BufferedOutputStream(
                fileOutputStream);

        myImage.compress(CompressFormat.JPEG, quality, bos);

        bos.flush();
        bos.close();

但我的图像在

Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);

请告诉我您的宝贵建议。

提前致谢:)

最佳答案

decodeByteArray 不会将 base 64 编码转换为字节数组。您需要先使用Base64 到字节数组转换器

关于android - BitmapFactory.decodeByteArray 在 android 中返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3511460/

相关文章:

android - 工具栏上的圆形 ImageView

android - 屏幕旋转时的 ViewModel 更新

android - html中的图像大或小

android - 如何在用户注册之前扫描 Firebase 数据库?

android - 使用绘图缓存为 WebView 设置动画。我这样做对吗?

android - 无法在 Android Studio 中设置 Android NDK 位置

android - 使用 KSOAP 调用 webservice 时获取 NumberFormatException

java - 我可以读取链接 key 表吗?

java - RTSP 描述 header 但没有响应

android - 如何复制android :editable ="false" in code?