各位大哥大姐帮忙看看啊,这是一个拍照程序,拍照好了已经得到了一个Bitmap bm ,但写不进文件
我用Log.e("photowaring","出错啦");调试
为什么下面的代码会报错写不了文件
PictureCallback myjpegCallback = new PictureCallback(){
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length);
ImageView myImageView = (ImageView) findViewById(R.id.myImageView);
myImageView.setImageBitmap(bm);//将图片显示到下方的ImageView中
/* 照片将被保存到  SD 卡跟目录下,文件名为系统时间,后缀名为".jpg" */  
//Log.e("phototest",bm.toString());
            File file = new File(Environment.getExternalStorageState(),"phototest.jpg");   
            try {   
                FileOutputStream fos = new FileOutputStream(file);   
                   
                /* 位图格式为JPEG  
                 * 参数二位 0-100 的数值,100为最大值,表示无损压缩   
                 * 参数三传入一个输出流对象,将图片数据输出到流中   
                 */  
                bm.compress(CompressFormat.JPEG, 100, fos);   
                fos.close();   
                   
                /* 拍完照后回到预览状态,继续取景 */  
                //camera.startPreview();   
            } catch (IOException e) {  
             Log.e("photowaring","出错啦");
                e.printStackTrace();   
            } 
isView = false;
myCamera.stopPreview();
myCamera.release();
myCamera = null;
initCamera();//初始化相机
}
};

解决方案 »

  1.   

    Environment.getExternalStorageState()  这个不是路径吧,File file = new File(Environment.getExternalStorageState(),"phototest.jpg"); 你这样建立的文件都不对啊
      

  2.   

    new File(Environment.getExternalStorageDirectory(),"*.jpg");
      

  3.   

    你新建文件代码错了,我是这么写的:
    String  SDPATH = Environment.getExternalStorageDirectory() + "/";  //获得当前外部存储设备的目录
    File file = new File(SDPATH + fileName);