0

我在将图像从 sd 卡加载到我的页面查看器时遇到问题。这是我得到的错误:

06-21 09:12:03.795: D/skia(881): --- decoder->decode returned false
06-21 09:12:03.795: I/System.out(881): resolveUri failed on bad bitmap uri: file:///sdcard/DinEgen/852-0.jpg
06-21 09:12:03.795: V/Fotski(881): file:///sdcard/DinEgen/852-0.jpg
06-21 09:12:03.795: D/skia(881): --- decoder->decode returned false
06-21 09:12:03.795: I/System.out(881): resolveUri failed on bad bitmap uri: file:///sdcard/DinEgen/852-1.jpg
06-21 09:12:03.795: V/Fotski(881): file:///sdcard/DinEgen/852-1.jpg
06-21 09:12:03.795: D/skia(881): --- decoder->decode returned false
06-21 09:12:03.795: I/System.out(881): resolveUri failed on bad bitmap uri: file:///sdcard/DinEgen/852-2.jpg
06-21 09:12:03.795: V/Fotski(881): file:///sdcard/DinEgen/852-2.jpg
06-21 09:12:03.795: D/skia(881): --- decoder->decode returned false
06-21 09:12:03.795: I/System.out(881): resolveUri failed on bad bitmap uri: file:///sdcard/DinEgen/852-3.jpg
06-21 09:12:03.795: V/Fotski(881): file:///sdcard/DinEgen/852-3.jpg

这是我添加新 imageView 的类:

public class ServiceImages1 extends LinearLayout{
    public ServiceImages1(Context context, String id) {
        super(context);
        init(id);
    }
    public ServiceImages1(Context context, AttributeSet attrs, String id) {
        super(context, attrs);
        init(id);
    }
    private void init(String id) {
        File file;
        file = new File("/sdcard/DinEgen/"+id);
        ImageView imageView = new ImageView(getContext());
        imageView.setImageURI(Uri.fromFile(file));
        Log.v("Fotski", ""+Uri.fromFile(file));




        addView(imageView);
    }
}

这是我的pageViewer:

    final MyPagerAdapter adapter = new MyPagerAdapter(this);
    viewPager.setAdapter(adapter);

    if( adapter.getCount() > 18){
        indicatorLayout.setVisibility(View.GONE);

    }
    viewPager.setOnPageChangeListener(new OnPageChangeListener() {

        public void onPageSelected(int page) {

            indicatorLayout.removeAllViews();
            for(int i = 0; i < adapter.getCount(); i++){
            if(i==page){
                indicatorLayout.addView(new IndicatorDotsView(getApplicationContext(), R.drawable.showpic_active));
            }else{
                indicatorLayout.addView(new IndicatorDotsView(getApplicationContext(), R.drawable.showpic_normal));
            }
        }

        }

        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        public void onPageScrollStateChanged(int arg0) {

        }
    });

}

public class MyPagerAdapter extends PagerAdapter {

    private ArrayList<LinearLayout> views;
    private ArrayList<LinearLayout> dots;

    public MyPagerAdapter(Context context) {
        views = new ArrayList<LinearLayout>();
        dots = new ArrayList<LinearLayout>();
        PhotoDao photoDb = new PhotoDaoImpl(context); 
        for(Photo photo: photoDb.findByParentType(parentType)){
            views.add(new ServiceImages1(context, photo.getFileName()));
        //photo.getFileName return picture name from sd card.   
        }


        for(int i = 0; i< getCount(); i++){
            if(i==0){
                dots.add(new IndicatorDotsView(context, R.drawable.showpic_active));
            }else{
                dots.add(new IndicatorDotsView(context, R.drawable.showpic_normal));
            }
        }

        for(int i = 0; i< getCount(); i++){
            indicatorLayout.addView(dots.get(i));
        }

    }

    @Override
    public void destroyItem(View view, int arg1, Object object) {
        ((ViewPager) view).removeView((LinearLayout) object);
    }

    @Override
    public void finishUpdate(View arg0) {

    }

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

    @Override
    public Object instantiateItem(View view, int position) {
        View myView = views.get(position);
        ((ViewPager) view).addView(myView);
        return myView;
    }

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

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1) {

    }

    @Override
    public Parcelable saveState() {
        return null;
    }

    @Override
    public void startUpdate(View arg0) {

    }

}

我不知道为什么这个解决方案不起作用。我只需要从 sd 卡中获取图片并将它们放入查看寻呼机。

4

0 回答 0