0
내 앱에서 사용자는 갤러리에서 아바타로 사진을 선택할 수 있지만 파일을 삭제할 수 있도록 내 앱 저장소에 저장하고 싶습니다.갤러리에서 앱 외부 저장소로 파일 저장하기
내 코드 :
//onActivityResult()
else if (requestCode == SELECT_PICTURE)
{
mFile = new File(getRealPathFromURI(data.getData()));
Date d = new Date();
long ms = d.getTime();
mName = String.valueOf(ms) + ".jpg";
copyfile(mFile,mName);
File file = new File(Environment.getExternalStorageDirectory(), mName);
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
imgPhoto.setImageBitmap(myBitmap);
}
public String getRealPathFromURI(Uri contentUri)
{
// can post image
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(contentUri,proj,null,null,null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
private void copyfile(File file,String newFileName){
try{
InputStream in = new FileInputStream(file);
OutputStream out = openFileOutput(newFileName, MODE_PRIVATE);
byte[] buf = new byte[4096];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
Log.d(null,"success");
}
catch(FileNotFoundException ex){
ex.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
}
제가 비트 맵을 디코딩 MFILE
경우, 이미지가 도시되어 MFILE 이미지를 갖도록. ¿ 어떤 아이디어?
팁 주셔서 감사합니다 !! ImageView에서 imagebitmap을 설정할 때 imageView가 투명하게 보이므로로드 할 데이터가없는 것 같습니다. 비트 맵에 mFile을로드하면 이미지가 나타나므로 이미지 검색이 괜찮다고 생각합니다. – JesusS