【发布时间】:2013-09-05 21:54:57
【问题描述】:
这是 mp3 文件标签中的图像 http://i.stack.imgur.com/HtXqA.jpg
我使用 Android 的 MediaMetaDataRetreiver 从 mp3 文件中获取此图像字节数组...当我尝试使用 BitmapFactory.decodeByteArray 解码此图像时,它返回 null
不胜感激
编辑:当我第一次使用 options.inJustDecodeBounds = true ... options.outWidth 和 options.outHeight 解码时返回正确的宽度和高度
完整代码:
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(context, songUri);
byte[] data = retriever.getEmbeddedPicture();
if(data != null)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, options);
options.inSampleSize = BitmapUtils.calculateInSampleSize(options, 500, 500);
options.inJustDecodeBounds = false;
albumArtBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
}
【问题讨论】:
-
你能贴出你的代码吗?
-
确实确实验证了 byte[] 实际上是您链接的文件? (例如,通过将其转储到文件系统,或在其上测量校验和)
-
您可以记录您为 inSampleSize 检索到的值吗?\
-
@njzk2 ...我将字节数组作为 jpg 转储到 sd ... android 无法显示图像(QuickPic -> 加载失败)...但是当我将其发送到我的计算机时图像显示正确......所以wtf编辑:是的文件与我发布的文件相同
-
@njzk2 ... inSampleSize 的值为 4,在 logcat 中有一个带有 tag="skia" 的日志,其 text="---decoder->decode 返回 false"