0

重複の可能性:
アクティビティ間でArrayList<Bitmap>を渡す方法

すべてのビットマップ配列要素を別のアクティビティに渡したいのですが、配列リストを渡すことはできますが、ビットマップ配列を渡すことはできません。インテント内のビットマップ配列に特別な命令はありますか?

4

4 に答える 4

1

Bitmapextends Parcelable、これは、次のようなリストを提供できることを意味します。

    ArrayList<Bitmap> bitmapList = new ArrayList<Bitmap>();
    // Poupulate list here

    Intent intent = new Intent();
    intent.putParcelableArrayListExtra("list", bitmapList);

Bitmap[]次に、これを受信アクティビティでに変換できます。

Bitmap[] bitmapArray = bitmapList.toArray(new Bitmap[bitmapList.size()]);

しかし、あなたの意図にあまりにも多くのものを入れることは一般的に悪い習慣であることを覚えておいてください。データ(DB、ファイルシステム、シングルトンなど)を保存し、URIまたはIDを渡すことをお勧めします。

于 2012-11-22T10:25:30.230 に答える
1

この問題を解決するには、以下の解決策を試してください。

1)最初に画像をバイト配列に変換してからarraylistに追加し、次にこのarraylistをIntentに渡し、次のアクティビティでバンドルからarraylistを取得し、Image(Bitmap)に変換してImageViewに設定します。

ビットマップをバイト配列に変換します:-

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

次に、このバイト配列をarraylistに追加します。

バイト配列をビットマップ画像に変換します:-

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);

image.setImageBitmap(bmp);
于 2012-11-22T10:41:30.360 に答える
0

//オブジェクトを渡す:

   intent.putExtra("MyClass", obj);

//2番目のアクティビティでオブジェクトを取得します

getIntent().getSerializableExtra("MyClass");
于 2012-11-22T10:32:52.373 に答える
0

ビットマップ配列を静的として使用し、別のアクティビティでclassname.bitmaparrayを使用します

于 2012-11-22T10:46:34.277 に答える