0

我有一些图像存储在内部存储器中。我设法检索图像文件位置并对其进行解码。但我无法让它显示在网格视图中。而且我不确定代码有什么问题,因为目前没有错误。任何意见将不胜感激。

    protected void onCreate(Bundle savedInstanceState) 
{   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.web_tab);
    helper = new DBHelper(this);
    Object[] values = helper.get_contentByEmailID(EMAIL);
    this.arrPath = new String[this.count];
    this.thumbnailsselection = new boolean[this.count];

    Log.i(TAG, "values:" +values);
    Log.i(TAG, "filepath:" +values[0]);
    Log.i(TAG, "filepath:" +values[1]);
    Log.i(TAG, "values:" +values.length);

    if(values.length>0){
        for (int i=0;i<values.length;i++){
            Log.i(TAG, "values[]" +values[i]);
            String bImage = (String) values[i];
            bitmap = new Bitmap [this.count];
            bitmap = decodeFile(bImage);


            Log.i(TAG, "bImage"+i+":" +bImage);
            Log.i(TAG, "bitmap"+i+":" +bitmap);
        }
    }
    else{
        Log.i(TAG, "Unable to locate images");
    }


    imagegrid = (GridView) findViewById(R.id.WebImageGrid);
    imageAdapter = new ImageAdapter();
    imagegrid.setAdapter(imageAdapter);


}

下面是 ImageAdapter 代码。

public class ImageAdapter extends BaseAdapter
{
    private Context mContext;       
    Bitmap[] mImageArray;
    private LayoutInflater mInflater;

    public ImageAdapter() {
        mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return count;
    }
    public Object getItem(int position)
    {
          return position;
    }
    public long getItemId(int position)
    {
          return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {  
            holder = new ViewHolder();
            convertView = mInflater.inflate(
                    R.layout.galleryitem, null);
            holder.imageview = (ImageView) convertView.findViewById(R.id.thumbImage);
            holder.checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox);

            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.checkbox.setId(position);
        holder.imageview.setId(position);


        holder.imageview.setImageBitmap(bitmap[position]);
        holder.checkbox.setChecked(thumbnailsselection[position]);
        holder.id = position;
        return convertView;
    }
}
class ViewHolder {
    ImageView imageview;
    CheckBox checkbox;
    int id;
}               

public Bitmap[] decodeFile(String filePath) 
{
    System.out.println("filepath in decode file .. "+filePath);
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, o);

    return bitmap;
}  

更新

    Object[] values = helper.get_wbm_synccontentByEmailID(SettingConstant.EMAIL);
    count=values.length;
    this.arrPath = new String[count];
    this.thumbnailsselection = new boolean[count];
    Log.i(TAG, "values:" +values.length);
    String bImage;
    if(count>0){
        bitmap = new Bitmap [count];

        for (int i=0;i<count;i++){
            Log.i(TAG, "values[]" +values[i]);
            bImage = (String) values[i];
            Bitmap newBitmap = decodeFile(bImage);
            this.arrPath[i] = bImage;
            this.bitmap[i] = newBitmap;

        }



    public Bitmap decodeFile(String filePath) 
{
    System.out.println("filepath in decode file .. "+filePath);
    Bitmap bitmapnew = BitmapFactory.decodeFile(filePath);

    return bitmapnew;
}   
4

2 回答 2

1

看看这个

decodeFile(String filePath)返回未在其中修改的位图。所以我认为位图根本没有改变(只是返回null)。

  1. 您正在传递一个文件路径并返回一个位图数组。您将获得一个位图图像并传递与位图数组相同的内容。

2.使用 bitmap[i] = decodeFile(bImage);而不是位图=decodeFile(bImage);

3.return type改为decodeFile(String filePath)简单bitmap

4.使用return BitmapFactory.decodeFile(filePath,o);而不是位图。

于 2012-12-10T10:33:57.783 回答
0

我认为你想从 getView 返回的是持有者而不是转换后的视图

于 2012-12-10T08:05:14.250 回答