Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决图片切换时的问题 #2

Open
MilesChan opened this issue Sep 16, 2015 · 3 comments
Open

解决图片切换时的问题 #2

MilesChan opened this issue Sep 16, 2015 · 3 comments

Comments

@MilesChan
Copy link

ImageActivity.java中替换showImage方法:
private void showImage(byte[] data)
{
Bitmap bitmap;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, opts);

    int size = (opts.outWidth * opts.outHeight);
    int size_limit = 1920 * 1080 * 4;
    if (size > 1920 * 1080 * 4) {
        int zoomRate = (int) Math.ceil(size * 1.0 / size_limit);
        if (zoomRate <= 0)
            zoomRate = 1;
        opts.inSampleSize = zoomRate;
    }

    if (!Thread.currentThread().isInterrupted()) {
        opts.inJustDecodeBounds = false;
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, opts);
        iv.setImageBitmap(bitmap);
    }
}

原因,由于部分图片过大,导致无法显示,因此应该在生成bitmap时做缩放处理(上述代码的作用是将
bitmap限制在1920*1080以内,毕竟大部分电视只支持1080p,分辨率高于这个意义不大,反而极易导致图片内存溢出等各种问题)
更新代码前,测试切换图片时部分图片不能显示的几率较大,更改后为0

@MilesChan
Copy link
Author

这个项目比较有意义,希望能坚持下去把他做好

@MilesChan
Copy link
Author

更正一下,还是不能杜绝问题,但确实明显有改善,基本上只要真的收到了请求,就能显示出来。尤其是投送高分辨率的图片时改善尤为明显

@gpfduoduo
Copy link
Owner

谢谢楼上的指正……我看一下,修改一下子

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants