intent 图片处理

从视图中提取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);


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值