android BitmapFactory.decodeStream质量低

时间:2015-05-10 17:38:06

标签: android bitmap

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

Bitmap myBitmap = BitmapFactory.decodeStream(myStream);

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

源也有高质量的图像。

我尝试使用Bitmap选项但没有改变:

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;
}

1 个答案:

答案 0 :(得分:2)

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

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

在LogCat中尝试mZip.getSize(); mZip.getCompressedSize(); mZip.getCrc();。具有不同质量的下载尝试的结果是否有所不同?我试图确定拉链下载是否在一段时间后停止,放弃,然后只显示它有的信息等