2
私は電話のギャラリーのすべてのjpegをリストする次のコードを持っています。それはうまく動作しますが、私は画像を選択したときに、選択した画像のデータで画像処理アクティビティの意図を起こしたいと思います。何か案は?事前にギャラリービューで選択した画像から画像データを取得する方法は?
感謝マット
Button useGallery = (Button)findViewById(R.id.loadfromgallery);
useGallery.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}}) ;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(selectedImage);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
if(yourSelectedImage != null){
Log.e(TAG,"pic ok");
}else{
Log.e(TAG,"pic not ok");
}
}
}
}
これを処理する方法は、データを渡すアプリケーションによって異なります。アプリケーションがビットマップのURIを予期している場合は、それをあなたの意図に余分に渡す必要があります。さもなければ、ビットマップを渡すことができます(それを行う方法を検索します)。ただし、たくさんのデータを送信しているので、これを行うことはお勧めしません。 – dymmeh