这是什么错误的原因,当uriString中:显示java.lang.NullPointerException:接收图像的SD卡路径
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.sqlfirst.AddImage}: java.lang.NullPointerException: uriString
错误是在该行所指之处我收到的意图
img.setImageURI(Uri.parse(imagePath));
我试图发送一个SD卡路径通过意图到另一个灵活性,并将其转换成图像 这是代码:
这里发送的路径e在SD卡中的图像
public void openGallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
// startActivityForResult(
// Intent.createChooser(intent, "Complete action using"),2);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {
Bundle extras2 = data.getExtras();
filePath = data.getData();
Intent i = new Intent(this,
AddImage.class);
i.putExtra("imagepath", filePath);
startActivity(i);
这里我想接收图像的路径并减小图像的大小。
String imagePath = getIntent().getStringExtra("imagePath");
ImageView img=(ImageView) findViewById(R.id.imageView);
img.setImageURI(Uri.parse(imagePath));
Bitmap bitmap = ((BitmapDrawable)img.getDrawable()).getBitmap();
Bitmap out = Bitmap.createScaledBitmap(bitmap, 500, 500, false);
// bitmap is the image
ByteArrayOutputStream stream = new ByteArrayOutputStream();
out.compress(Bitmap.CompressFormat.JPEG, 60, stream);
bitmap.recycle();
优秀..我可以解释为什么如何从其他活动获取uri并将其转换为图像?呃帮助ia真正apreciate – Moudiz
@Moudiz更新了我的答案;) – Angmar
谢谢你生病检查它现在 – Moudiz