从视图中提取image 并转换成byte[] 通过intent转发
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent intent = new Intent(context, NewsOneItem.class);
// Bundle bundle = new Bundle();
NewsBean nb = nbs.get(position);
intent.putExtra("nb", nb);
// bundle.putString("title", nb.getTitle());
// bundle.putString("content", nb.getContent());
ImageView iv = (ImageView) view.findViewById(R.id.la_image);
Drawable drawable = iv.getDrawable();
BitmapDrawable bd = (BitmapDrawable) drawable;
Bitmap bm = bd.getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
intent.putExtra("image", baos.toByteArray());
intent.putExtra("all", nbs);
// intent.putex
context.startActivity(intent);
}
}
接收
Intent intent = getIntent();
byte[] b = intent.getByteArrayExtra("image");
NewsBean nb = intent.getParcelableExtra("nb");
System.out.println(intent.getParcelableArrayExtra("all"));
source.setText("来自:" + nb.getSource() + " 发布日期"
+ nb.getRelease_time());
title.setText(nb.getTitle());
content.setText(nb.getContent());
Bitmap bm = BitmapFactory.decodeByteArray(b, 0, b.length);
//一定要设置 可见 帮助文档
imageview.setAdjustViewBounds(true);
imageview.setMaxHeight(100);
imageview.setImageBitmap(bm);