public void testHandler (View v)
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, REQUEST_GALLERY);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_GALLERY) {
Toast.makeText(getApplicationContext(),
"Start", Toast.LENGTH_SHORT).show();
try{
InputStream is = getContentResolver().openInputStream(data.getData());
Bitmap bm = BitmapFactory.decodeStream(is);
is.close();
ImageView img = (ImageView)findViewById(R.id.testImg);
img.setImageBitmap(bm);
}catch(Exception e){
Toast.makeText(getApplicationContext(),
"Error:"+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
2011年6月7日火曜日
保存されている画像を取得する。
layout には ImageView を設置して onClick="testHandler" とする。
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿