将bitmap图像设置为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卡上,我可以看到它,名称和路径是正确的。它只是没有出现。任何想法都是我的错误?
答案 0 :(得分:3)
我认为getView永远不会被调用,因为你的适配器返回你有0个项目。尝试返回您要显示的该位图的1或多个实例的计数。