2011-10-25 15 views
0

ImageViewのソースとしてビットマップイメージを設定する際に少し問題があります。ここで私が使用していたコードは次のとおりです。Android ImageViewビットマップをソースとして設定

BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inTempStorage = new byte[16*1024]; 

    String path = Environment.getExternalStorageDirectory()+"/Stampii/"+objectId+".png"; 
    Log.i("","path : "+path); 

    b = BitmapFactory.decodeFile(path,options); 
    if(b==null){ 
     Log.i("","Bitmap is null"); 
    } 

viewFlow = (ViewFlow) findViewById(R.id.viewflow); 
     viewFlow.setAdapter(new ImageAdapter(Cards.this, b),position); 
ここ

は、私は、画像を保存しています方法です:

File myDir=new File("/sdcard/Stampii"); 
        myDir.mkdirs(); 

        String filename = objectId+".png"; 
        File file = new File(myDir, filename); 
        FileOutputStream fos; 


        fos = new FileOutputStream(file); 
        fos.write(mediaCardBuffer); 
        fos.flush(); 
        fos.close(); 

ImageAdapter:

ublic class ImageAdapter extends BaseAdapter { 

private LayoutInflater mInflater; 

private Bitmap bitmap; 

public ImageAdapter(Context context, Bitmap image) { 
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    bitmap = image; 
} 

@Override 
public int getCount() { 
    return 0; 
} 

@Override 
public Object getItem(int position) { 
    return position; 
} 

@Override 
public long getItemId(int position) { 
    return position; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    if (convertView == null) { 
     convertView = mInflater.inflate(R.layout.image_item, null); 
    } 
    ((ImageView) convertView.findViewById(R.id.imgView)).setImageBitmap(bitmap); 
    return convertView; 
}} 

画像は私が見ることができますSDカード上にありますそれと名前とパスは正しいです。それは表示されません。私の間違いはどこですか?

答えて

3

あなたはアダプタが0個のアイテムを持っていることを返しているので、getViewが呼び出されることはないと思います。表示するビットマップの数が1になるか、多くのインスタンスが返されるようにしてください。

関連する問題