gpt4 book ai didi

android BitmapFactory.decodeStream 低质量

转载 作者:行者123 更新时间:2023-11-29 00:11:02 24 4
gpt4 key购买 nike

我正在尝试将输入流解码为位图,代码非常简单:

Bitmap myBitmap = BitmapFactory.decodeStream(myStream);

但输出位图的质量太低(有时,有时质量很好)。

来源也有高质量的图像。

我尝试使用位图选项但没有任何改变:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap myBitmap = BitmapFactory.decodeStream(myStream, null, options);

那么,我怎样才能得到完整质量的位图呢?

更新 1:

我将这张图片用于动画,如下所示:

coverAnimationImage.post(new Runnable()
{
Override
public void run()
{
try
{
InputStream coverStream = getCoverStream();
if(coverStream != null)
{
bookCover = BitmapFactory.decodeStream(coverStream);
}
}
catch (Exception e)
{
// no cover
}
coverAnimationImage.setImageBitmap(bookCover);
mBackground = new ColorDrawable(Color.BLACK);
if(Build.VERSION.SDK_INT >= 16)
{
coverAnimationLayout.setBackground(mBackground);
}
else
{
coverAnimationLayout.setBackgroundDrawable(mBackground);
}
if (flag)
{
ViewTreeObserver observer = coverAnimationImage.getViewTreeObserver();
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
{
@Override
public boolean onPreDraw()
{
coverAnimationImage.getViewTreeObserver().removeOnPreDrawListener(this);
int[] screenLocation = new int[2];
coverAnimationImage.getLocationOnScreen(screenLocation);
mLeftDelta = coverLeft - (screenLocation[0]);
mTopDelta = coverTop - (screenLocation[1]);
mWidthScale = (float) coverWidth / coverAnimationImage.getWidth();
mHeightScale = (float) coverHeight / coverAnimationImage.getHeight();
runEnterAnimation();
return true;
}
});
}
}
});

我想当我运行动画时 BitmapFactory.decodeStream 还没有完成它的工作!是否可以?或者知道这里发生了什么?

更新 2:图像信息

enter image description here

更新 3:

低质量图像:

enter image description here

高质量:

enter image description here

内存监视器:

enter image description here

YouTube 视频:

android BitmapFactory.decodeStream low quality

更新 4:

getCoverStream 代码:

protected InputStream getCoverStream() 
{
String fileName = getCoverAddress();
InputStream in = null;
ZipEntry containerEntry = mZip.getEntry(fileName);
if (containerEntry != null)
{
try
{
in = mZip.getInputStream(containerEntry);
}
catch (IOException e)
{
Log.e(TAG, "Error reading zip file " + fileName, e);
}
}

if (in == null)
{
Log.e(TAG, "Unable to find file in zip: " + fileName);
}

return in;
}

最佳答案

这实际上可能不是 BitmapFactory.decodeStream() 的问题,因为默认情况下 decodeStream 解码全分辨率数据。

我们看到您正在使用 ZipEntry。这可能是流未完全下载或流 (getCoverStream) 未被调用的问题。

试试 mZip.getSize(); mZip.getCompressedSize(); mZip.getCrc(); 在 LogCat 中。结果是否因不同质量的下载尝试而异?我正在尝试确定 zip 下载是否在一定时间后停止、放弃,然后只显示它拥有的信息等

关于android BitmapFactory.decodeStream 低质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30154521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com