你好,我试图保存在我的应用程序上拍摄的照片,但当我试图访问内存以放置数据时,会出现错误
无法解码流java.io.FileNotFoundException/storage/emulated/0打开失败:enoint(没有这样的文件或目录)
这是我的代码。
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
// TODO Auto-generated method stub
if (data != null){
//Intent mIntent = new Intent();
//mIntent.putExtra("image",imageData);
mCamera.stopPreview();
mPreviewRunning = false;
mCamera.release();
try{
BitmapFactory.Options opts = new BitmapFactory.Options();
Bitmap bitmap= BitmapFactory.decodeByteArray(data, 0, data.length,opts);
bitmap = Bitmap.createScaledBitmap(bitmap, 300, 300, false);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int newWidth = 300;
int newHeight = 300;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(-90);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
width, height, matrix, true);
Camera_local_db.image.setImageBitmap(resizedBitmap);
}catch(Exception e){
e.printStackTrace();
}
// StoreByteImage(mContext, imageData, 50,"ImageName");
//setResult(FOTO_MODE, mIntent);
setResult(585);
finish();
}
}
};
Camera.PictureCallback jpegCallback = new Camera. PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File dir_image2 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),"dddd.jpg");
dir_image2.mkdirs(); //AGAIN CHOOSING FOLDER FOR THE PICTURE(WHICH IS LIKE A SURFACEVIEW
//SCREENSHOT)
if (!dir_image2.mkdirs()) {
Log.e(TAG, "Directory not created");
}
File tmpFile = new File(dir_image2,"TempGhost.jpg"); //MAKING A FILE IN THE PATH
//dir_image2(SEE RIGHT ABOVE) AND NAMING IT "TempGhost.jpg" OR ANYTHING ELSE
try {//SAVING
FileOutputStream fos = new FileOutputStream(tmpFile);
fos.write(data);
fos.close();
//grabImage();
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
}
//String path = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_MOVIES); File file = new File(path, "/" + dir_image2);
//String path = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)+
// File.separator+"TempGhost.jpg");//<---
BitmapFactory.Options options = new BitmapFactory.Options();//<---
options.inPreferredConfig = Bitmap.Config.ARGB_8888;//<---
bmp1 = BitmapFactory.decodeFile(tmpFile.toString(), options);//<---
//THE LINES ABOVE READ THE FILE WE SAVED BEFORE AND CONVERT IT INTO A BitMap
Camera_local_db.image.setImageBitmap(bmp1);
//camera_image.setImageBitmap(bmp1); //SETTING THE BitMap AS IMAGE IN AN IMAGEVIEW(SOMETHING
//LIKE A BACKGROUNG FOR THE LAYOUT)
// TakeScreenshot();//CALLING THIS METHOD TO TAKE A SCREENSHOT
}
};
您需要写入外部存储,请确保您添加了权限:
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>
检查外部存储是否可用于读写:
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
使用公共目录的根目录,而不是使用Android的根目录。
如果要在外部存储上保存公共文件,请使用getExtranalStoragePublicDirectory()
public File getAlbumStorageDir(String albumName) {
// Get the directory for the user's public pictures directory.
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM), albumName);
if (!file.mkdirs()) {
Log.e(LOG_TAG, "Directory not created");
}
return file;
}
如果要保存应用程序专用的文件,请使用getExternalFilesDir()命令
public File getAlbumStorageDir(Context context, String albumName) {
// Get the directory for the app's private pictures directory.
File file = new File(context.getExternalFilesDir(
Environment.DIRECTORY_DCIM), albumName);
if (!file.mkdirs()) {
Log.e(LOG_TAG, "Directory not created");
}
return file;
}
有关链接的更多信息http://developer.android.com/training/basics/data-storage/files.html
不幸的是,什么也没有发生,只是这样:无法解码流:java.io.FileNotFoundException:/com.marijan.red.messageActivity@dac48b3/document/image:256(没有这样的文件或目录) 我假设我没有正确地通过图像
问题内容: 我想解码从画廊拍摄的照片,但是有错误。我尝试了各种方法,但没有一个成功。请帮助修复我的代码。 这是我的代码:https : //pastebin.com/syWjqPDK } 这是logcat的结果 问题答案: 从画廊的乐趣中选择图像,如下所示: onActivityResult像这样: 获取像这样的位图扩展名: 祝好运
我试着从图库中打开图像并在Imageview中显示相同的活动。我添加了WRITE_EXTERNAL_STORAGE、READ_EXTERNAL_STORAGE、internet等权限。当我从图库中选择图像并返回活动时,它会显示这种类型的错误 09-04 15:02:57.161 316 42-31642/com.androidTutorialPoint.qrcodescanner E/Bitmap
我有一个错误: 警告:require_once(../questionTypes/Question.php):无法打开流:第25行的/home/u949913003/public_html/includes/essential.php中没有此类文件或目录 致命错误:require_once():无法在/home/u949913003/public_html/includes/essential.p
你好,我试图保存图片从网址在我的应用程序,但当我试图访问内存放置数据,一个错误出来 无法解码流java.io.FileNotFoundException/storage/emulated/0打开失败:enoint(没有这样的文件或目录) 这是我的DownloadManager课程 这是我的下载请求类: 这是我的G班: