问题描述
我希望将图像从一个活动传递给另一个活动.我想知道是否有可能这样做.
发送活动
Intent intent = new Intent(getApplicationContext(), BitmapActivity.class); Bundle b = new Bundle(); b.putParcelable("BITMAP", bitmap); intent.putExtras(b); startActivity(intent);
接收活动
Bundle bb = this.getIntent().getExtras(); b = bb.getParcelable("BITMAP");
但我得到 !!!失败的粘合剂交易!!! 错误
推荐答案
您可以使用包含静态位图对象的全局类,如下所示:
public class Global { static Bitmap img; }
在通过意图阐述活动之前,将位图分配给此全局类属性:
Global.img = your_bitmap_img;
启动活动后,您可以通过以下方式返回您的位图:
bitmap_in_new_activity = Global.img;
我知道全局变量对于调试太危险,但这种技术有助于我们将大数据从一个活动转移到另一个活动.除了您的设备功能或您的应用程序时,粘合剂事务缓冲区具有有限的固定大小,目前为1MB.
其他推荐答案
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.f1); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] food = stream.toByteArray(); Intent intent = new Intent(MainActivity.this,NoBoringActionBarActivity.class); intent.putExtras(bundle); intent.putExtra("picture", food); startActivity(intent);
发送活动
Bundle extras = getIntent().getExtras(); byte[] food = extras.getByteArray("picture"); Bitmap fo = BitmapFactory.decodeByteArray(food, 0, food.length); mHeaderLogo = (ImageView) findViewById(R.id.header_logo); //ImageView image = (ImageView) findViewById(R.id.header_logo); mHeaderLogo.setImageBitmap(fo);
接收活动
别忘了把你的图像放在drawable中.
问题描述
I want to pass a image as a bitmap from one activity to another. And i want to know whether it is possible to do like that.
Sending Activity
Intent intent = new Intent(getApplicationContext(), BitmapActivity.class); Bundle b = new Bundle(); b.putParcelable("BITMAP", bitmap); intent.putExtras(b); startActivity(intent);
Receiving Activity
Bundle bb = this.getIntent().getExtras(); b = bb.getParcelable("BITMAP");
But i am getting !!! FAILED BINDER TRANSACTION !!! Error
推荐答案
You can use a global class with a static bitmap object in it, something like this:
public class Global { static Bitmap img; }
Before stating the activity by intent, assign your bitmap to this Global class attribute:
Global.img = your_bitmap_img;
After starting your activity, you can get back your bitmap by:
bitmap_in_new_activity = Global.img;
I know global variables are too dangerous for debugging but this technique helps us to transfer large data from one activity to another.The binder transaction buffer has a limited fixed size, currently 1Mb regardless of your device capabilities or your app.
其他推荐答案
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.f1); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] food = stream.toByteArray(); Intent intent = new Intent(MainActivity.this,NoBoringActionBarActivity.class); intent.putExtras(bundle); intent.putExtra("picture", food); startActivity(intent);
Sending Activity
Bundle extras = getIntent().getExtras(); byte[] food = extras.getByteArray("picture"); Bitmap fo = BitmapFactory.decodeByteArray(food, 0, food.length); mHeaderLogo = (ImageView) findViewById(R.id.header_logo); //ImageView image = (ImageView) findViewById(R.id.header_logo); mHeaderLogo.setImageBitmap(fo);
Receiving Activity
Don't forget to place your image in drawable.