在这里,我不存储我捕获的图片。它在图像视图中显示,但我试图保存图像,但图像不显示在图像视图中。无法保存位图图像
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1;
private static int RESULT_LOAD_IMG = 1;
String imgDecodableString;
ImageView iv;
Bitmap bmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.imgView);
Button b = (Button) findViewById(R.id.buttonLoadPicture);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectImage();
}
});
}
public void selectImage() {
final CharSequence[] options = { "Take Photo", "Choose from Gallery","Cancel" };
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Add Photo!");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Take Photo")) {
String path = Environment.getExternalStorageDirectory() + "/CameraImages/example.jpg";
File file = new File(path);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, 1);
} else if (options[item].equals("Choose from Gallery")) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 2);
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
if (data != null && data.getExtras() != null) {
bmp = (Bitmap) data.getExtras().get("data");
Log.w("path of image from gallery......******************.........", bmp + "");
iv.setImageBitmap(bmp);
}
}else {
if (requestCode == 2) {
Uri selectedImage = data.getData();
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor c = getContentResolver().query(selectedImage, filePath, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
String picturePath = c.getString(columnIndex);
c.close();
bmp = (BitmapFactory.decodeFile(picturePath));
Log.w("path of image from gallery......******************.........", picturePath + "");
iv.setImageBitmap(bmp);
}
}
}}}
当加法intent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri );图像被保存但在图像视图
检查这,这将帮助你在我的应用程序,其工作代码:HTTP://stackoverflow.com/questions/34923702/android-getting-pictures-from-photos-galery-error-on-some-devices/34942980#349429 80个 –
嗨苏哈斯,UR链接是从画廊实际上多数民众赞成在为我工作我想是我需要甚至可以保存图像时我在相应的像场 –
显示它是我张贴保存图像的答案提取图像。 –