无法在不损失质量或导致内存异常的情况下将图像加载到PhotoView中

时间:2016-01-27 01:06:43

标签: android picasso android-glide

我使用Glide将图像加载到PhotoView中以创建具有缩放和多页的可视化,但是即使将格式设置为DecodeFormat.PREFER_ARGB_8888,缩放时图像质量也会很差。

然后我去了毕加索,但是对于1028 x 1580像素的图像,它导致内存不足异常。如何以更好的质量显示此图像,允许缩放和切换页面(如果我在WebBrowser上显示它们,即使在缩放时质量也更好)?

以下是PagerAdapter的代码:

static class SamplePagerAdapter extends PagerAdapter {

        private final List<Uri> pageList;

        public SamplePagerAdapter(List<Uri> pageList) {
            this.pageList = pageList;
        }

        @Override
        public int getCount() {
            return pageList.size();
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            /*Glide.with(container.getContext())
                    .load(pageList.get(position))
                    .asBitmap()
                    .format(DecodeFormat.PREFER_ARGB_8888)
                    .into(photoView);*/

            Picasso.with(container.getContext()).load(pageList.get(position)).into(photoView);

            // Now just add PhotoView to ViewPager and return it
            container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

            return photoView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

    }

0 个答案:

没有答案