我有一個應用程序,我必須從相機活動中捕獲圖像,並使用內容解析程序將該圖像插入到媒體中。 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