AirPlay-Receiver-on-Android icon indicating copy to clipboard operation
AirPlay-Receiver-on-Android copied to clipboard

解决图片切换时的问题

Open MilesChan opened this issue 9 years ago • 3 comments

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 avatar Sep 16 '15 14:09 MilesChan

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

MilesChan avatar Sep 16 '15 14:09 MilesChan

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

MilesChan avatar Sep 17 '15 04:09 MilesChan

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

gpfduoduo avatar Sep 17 '15 12:09 gpfduoduo