0

カメラまたはギャラリーから画像(URLではなく)をロードして、グローバルクラスに保存しようとしています。(現時点では、画像にアクセスしようとしていますが、クラスはまだ定義されていません)。

ですから、カメラは画像を正しく返し、それをバンドルに入れると思います。可能であれば、ギャラリーにも同じアプローチを使用したいと思います。

ので、私は持っています:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode==RESULT_OK){
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");

    }
} 

そして、この2つの選択は、明らかに私がギャラリーで何か間違ったことをしているところです。

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub
    switch(arg2){
    case 0:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, cameraData);
        break;
    case 1:

        Intent intent = new Intent( Intent.ACTION_GET_CONTENT );
        intent.setType( "image/*" );

        //i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(intent, 10); 
        break;
    }

結果の配信に失敗しました:リソースのnullポインター例外:dat = content:// media / external / images / media / 23

だから私は何か間違ったことをしていると思います。

アイデアはInstagramで見られる動作に似ており、写真を撮るか、既存のものを選択します。選択すると、アプリ内に画像が再び表示される前に選択できるオプションがさらに3つあるため、シングルトーンオブジェクトに保存する必要があります。

これが画像を処理するための最適な方法であるかどうかはわかりませんので、ここでの提案も歓迎します。

Tnx

4

1 に答える 1

1

onActivityResult、このコードを試してください。

InputStream in = getContentResolver().openInputStream(data.getData());
// get picture size.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(in, null, options);
in.close();
// resize the picture for memory.
int width = options.outWidth / displayWidth + 1;
int height = options.outHeight / displayHeight + 1;
int sampleSize = Math.max(width, height);
options.inSampleSize = sampleSize;
options.inJustDecodeBounds = false;
in = getContentResolver().openInputStream(data.getData());
// convert to bitmap with declared size.
Bitmap bitmap = BitmapFactory.decodeStream(in, null, options);
in.close();
于 2012-09-19T09:32:30.367 に答える