안드로이드 개발 질문/답변
(글 수 45,052)
첫번째 엑티비티에서
myimage = (ImageView)findViewById(R.id.mypic);
myimage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_PICK);
i.setType(android.provider.MediaStore.Images.Media.CONTENT_TYPE);
i.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); // images on the SD card.
startActivityForResult(i, REQ_CODE_PICK_PICTURE);
}
});
를 넣어서 갤러리를 불러왔습니다.
여기서 이미지를 선택해서 원하는 위치에 아래의 코드로 넣었습니다.
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == REQ_CODE_PICK_PICTURE) {
if (resultCode == Activity.RESULT_OK) {
ImageView img = (ImageView)findViewById(R.id.mypic);
img.setImageURI(data.getData());
}
}
}
음... 그런데... 선택한 이미지를 DB에 넣어서 다른 액티비티에 리스트뷰로 뿌려줄때 사진데이터로 불려져야하거든요... 이거 어디 소스를 건들여서 넣어야하는지 모르겠습니다. 알려주시와요~ ㅠ_
2010.11.19 14:06:15
자답입니다.
엑티비티 생성 후 Uri에 대한 선언을 합니다.
Uri iuri;
그리고 onActivityResult에서 사진을 뿌려줄때
iuri= intent.getData();
Images.Media.getBitmap( getContentResolver(), iuri);
ImageView img = (ImageView)findViewById(R.id.mypic);
img.setImageURI(iuri);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
이렇게 설정하면 사진이 이미지뷰에 표시됩니다. DB에 저장할때에는 iuri.toString() 으로 저장하니 잘 되었습니다.
지금은... 다시 불러와서 사진을 뿌려주는게 막히네요 ㅠ



