我有一个应用程序,我必须从相机活动中捕获图像,并使用内容解析程序将该图像插入到媒体中。 EXTERNAL_CONTENT_URI和我有getString()该图像的路径,并通过它捆绑在其他活动。Android:从指定路径获取图像的问题
从那里,我已经得到该路径,并把它放在位图bitmap = BitmapFactory.decodeFile(filepath);
但它显示FILENOTFOUNDEXCEPTION和NULLPOINTEREXCEPTION.How解决这个问题?
所以我也尝试另一种方法,使得我在第一个活动中得到的图像应该先设置为一个文件,然后我轻松解码该文件?
请建议我这样做。
更新 - >
CODE: `//pass image path to other activity`
case PICK_FROM_CAMERA : if (resultCode == RESULT_OK)
{
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
values.put(Images.Media.MIME_TYPE,"image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
filepath = uri.getPath();
Bitmap photo = (Bitmap) data.getExtras().get("data");
//((ImageView)findViewById(R.id.selectedimage)).setImageBitmap(photo);
OutputStream outstream;
try
{
outstream = getContentResolver().openOutputStream(uri);
photo.compress(Bitmap.CompressFormat.JPEG,100,outstream);
outstream.close();
}
catch (FileNotFoundException e) {}
catch (IOException e) {}
Intent intent = new Intent(this.getApplicationContext(),AnimationActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("flag", 0);
bundle.putString("filepath", filepath);
intent.putExtras(bundle);
startActivity(intent);
}
Code: //show that image
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img = (ImageView)findViewById(R.id.background);
Bitmap border = BitmapFactory.decodeResource(getResources(),R.drawable.border1);
Bundle extra = getIntent().getExtras();
mfilepath = extra.getString("filepath");
int flag = extra.getInt("flag");
if(flag==1)
{
bgr= BitmapFactory.decodeFile(mfilepath);
}
if(flag==0)
{
bgr=BitmapFactory.decodeFile(mfilepath);
OutputStream outstream;
try
{
outstream = getContentResolver().openOutputStream(Uri.fromFile(new File(mfilepath)));
//bgr.compress(Bitmap.CompressFormat.JPEG,100,outstream);
outstream.close();
}
catch (FileNotFoundException e) {}
catch (IOException e) {}
}
bmOverlay = Bitmap.createBitmap(border.getWidth(),border.getHeight(),bgr.getConfig());
canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmOverlay, 0, 0, null);
canvas.drawBitmap(bgr, 0, 0, null);
canvas.drawBitmap(border,0,0, null);
canvas.save();
img.setImageBitmap(bmOverlay);
想要将图像设置为文件吗?哪个文件?什么样的文件? –
可否请您上传一些代码?这是很难说,没有代码... – Kgrover
我已经清除马问题,请检查它... – Geetanjali