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卡,我可以看到它和名称和路径是正确的。它只是没有出现。任何想法是我的错误?