0
カメラで撮影した画像を表示しようとしていますが、動作することがありますが、通常エラーが表示されます:カメラから撮影した画像を表示:android.graphics.BitmapFactory.nativeDecodeStream(デフォルトのメソッド)のjava.lang.OutOfMemoryError
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:727)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:703)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:741)
at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:847)
at com.dima.polimi.rentall.NewProduct.onActivityResult(NewProduct.java:207)
at android.app.Activity.dispatchActivityResult(Activity.java:5773)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3710)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3757)
at android.app.ActivityThread.access$1400(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5635)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
は、私は、複数の質問から解決策を試してみましたが、私はそれが
動作するように作ることはありませんこれは私のコードです:
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dispatchTakePictureIntent();
}
});
dispatchTakePictureIntent
String mCurrentPhotoPath;
private void dispatchTakePictureIntent() {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
Log.i("", "IOException");
}
// Continue only if the File was successfully created
if (photoFile != null) {
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(cameraIntent, REQUEST_TAKE_PHOTO);
}
}
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, // prefix
".jpg", // suffix
storageDir // directory
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
try {
Bitmap mImageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mCurrentPhotoPath));
mImageView.setImageBitmap(mImageBitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
は、[画像ローディングライブラリ](HTTPSを使用しますandroid-arsenal.com/tag/46)、[Picasso](https://github.com/square/picasso)のように、画像をインテリジェントにダウンサンプリングして 'ImageView'に合うようにすることができます。また、ここでやっているように、メインのアプリケーションスレッドでその作業を行うのではなく、バックグラウンドスレッドでその作業を行います(UIがフリーズしている間に)。 – CommonsWare
@CommonsWare私は試してみました:Picasso.with(this).load(mCurrentPhotoPath).into(mImageView);それはロードされません – Juan
'mCurrentPhotoPath'は有効なファイルシステムパスでも有効な' Uri'でもありません。 'image'をホールドし、' File'オブジェクトを使ってみてください。 – CommonsWare