ギャラリーから画像をAndroidアプリケーションに取り込む方法は?モバイルギャラリーから画像をAndroidアプリケーションに取り込む方法
私のギャラリーから画像をブラウズして、自分のアプリを選択する必要があります。できますか?
ギャラリーから画像をAndroidアプリケーションに取り込む方法は?モバイルギャラリーから画像をAndroidアプリケーションに取り込む方法
私のギャラリーから画像をブラウズして、自分のアプリを選択する必要があります。できますか?
あなたはギャラリー(よく「ギャラリー」)の意図を使用する必要があります。
あなたがここでのコード例を見つけることができますは(私はそれを行っていないが、それは動作しますように見えます): http://www.androidsnippets.com/get-file-path-of-gallery-image
使用このコード:
fromGalleryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//takePhotoFromGallery = true;// edited
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);//
startActivityForResult(Intent.createChooser(intent, "Select Picture"),10);
}
});
そして、これを追加します。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 10 && resultCode == Activity.RESULT_OK) {
Uri contentUri = data.getData();
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();
imagePath = cursor.getString(column_index);
tempBitmap = BitmapFactory.decodeFile(imagePath); // this is your image
}
}
このページの右側にある[関連する] Q&Aを見てください。あなたの質問に対処する方法がいくつかあります。 –