Android中傳遞圖片的2種方法
方法一:
基本思路是先把bitmap轉(zhuǎn)化為byte數(shù)組,用Intent傳遞數(shù)組,在將數(shù)組轉(zhuǎn)化為bitmap
bitmap轉(zhuǎn)化為byte數(shù)組的方法:
private byte[] Bitmap2Bytes(Bitmap bm){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
byte數(shù)組轉(zhuǎn)化為bitmap方法:
byte buff[]=mIntent.getByteArrayExtra("image");
bitmap = BitmapFactory.decodeByteArray(buff, 0, buff.length);
方法2:
發(fā)送圖片:
Intent intent = new Intent(ChangePortraitActivity.this , UserProfileActivity.class);
mImageView.setDrawingCacheEnabled(Boolean.TRUE);
intent.putExtra("BITMAP", mImageView.getDrawingCache()); //這里可以放一個(gè)bitmap
startActivity(intent);
接收?qǐng)D片:
//接收的activity
Intent intent = getIntent();
if (intent != null && intent.getParcelableExtra("BITMAP") != null) {
Bitmap bitmap = (Bitmap)getIntent().getParcelableExtra("BITMAP");
mImageViewPortrait.setImageBitmap(bitmap);
}
相關(guān)文章
Android系統(tǒng)默認(rèn)對(duì)話框添加圖片功能
這篇文章主要介紹了Android系統(tǒng)默認(rèn)對(duì)話框添加圖片的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01

Android下使用TCPDUMP實(shí)現(xiàn)數(shù)據(jù)抓包教程

Android仿微信照片選擇器實(shí)現(xiàn)預(yù)覽查看圖片

Android仿考拉全局滑動(dòng)返回及聯(lián)動(dòng)效果的實(shí)現(xiàn)方法

Android利用Gson解析嵌套多層的Json的簡(jiǎn)單方法

Android自定義照相機(jī)Camera出現(xiàn)黑屏的解決方法