在我的应用程序中,我将 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/