intent 图片处理

来源:互联网 发布:蛋疼到底有多疼 知乎 编辑:程序博客网 时间:2024/06/06 12:24

从视图中提取image 并转换成byte[] 通过intent转发

@Overridepublic 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.putexcontext.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);


 

原创粉丝点击