카메라에서 이미지를 캡처해야하는 앱이 있고 콘텐츠 리졸버를 사용하여 이미지를 미디어에 삽입했습니다. EXTERNAL_CONTENT_URI 그리고 getString() 이미지의 경로가 있고 다른 활동에서 번들로 전달했습니다.Android : 지정된 경로에서 이미지를 가져 오는 중 문제가 발생했습니다.
그 경로를 가져 와서 Bitmap에 넣으십시오. bitmap = BitmapFactory.decodeFile (filepath);
하지만 FILENOTFOUNDEXCEPTION 및 NULLPOINTEREXCEPTION이 표시됩니다. 해결 방법은 무엇입니까?
그래서 나는 첫 번째 활동에서 얻은 이미지를 먼저 파일로 설정 한 다음 그 파일을 쉽게 디코딩해야한다는 또 다른 접근법을 시도하고 있습니까?
제게 그 방법을 제안하십시오.
UPDATES ->
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