Ars*_*han 9 android imageview android-activity
我必须将图像从一个活动转移到另一个活动.在第一个活动中,用户从滚动视图中选择几个图像中的图像,并且该图像必须显示在下一个活动的图像视图中.需要帮助.
在你的第一个活动中
将ImageView转换为位图
    imageView.buildDrawingCache();
    Bitmap bitmap = imageView.getDrawingCache();
    Intent intent = new Intent(this, NewActivity.class);
    intent.putExtra("BitmapImage", bitmap);
在第二个活动中
     Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
然后在ImageView中显示位图.
注意:不建议这样做.实际应该将图像保存在某处并传递路径并从第二个活动中检索.
小智 6
您可以将其作为字节数组传递,并构建位图以便在下一个活动中显示.例如:
在您的第一个活动中:
Intent i = new Intent(this, NextActivity.class);
Bitmap b; // your bitmap
ByteArrayOutputStream bs = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 50, bs);
i.putExtra("byteArray", bs.toByteArray());
startActivity(i);
在你的第二个活动中
if(getIntent().hasExtra("byteArray")) {
    ImageView previewThumbnail = new ImageView(this);
    Bitmap b = BitmapFactory.decodeByteArray(
        getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);        
    previewThumbnail.setImageBitmap(b);
}
| 归档时间: | 
 | 
| 查看次数: | 34590 次 | 
| 最近记录: |