最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程使用Intent傳遞圖片的方法詳解

 更新時(shí)間:2017年02月27日 10:28:22   作者:Jacob-wj  
這篇文章主要介紹了Android編程使用Intent傳遞圖片的方法,結(jié)合實(shí)例形式分析了Android基于Intent傳輸圖片的原理與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程使用Intent傳遞圖片的方法。分享給大家供大家參考,具體如下:

基本思路是先把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);

程序?qū)嵗?/p>

第一個(gè)activity:

import java.io.ByteArrayOutputStream;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class SendImageActivity extends Activity implements OnClickListener {
  /** Called when the activity is first created. */
  private Bitmap bitmap;
  byte buff[] = new byte[125*250];
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView mImageView = (ImageView) findViewById(R.id.image);
    Button bt1 = (Button) findViewById(R.id.bt1);
    bitmap =BitmapFactory.decodeResource(getResources(), R.drawable.option24);
    buff = Bitmap2Bytes(bitmap);
    BitmapDrawable mBitmapDrawable = new BitmapDrawable(bitmap);
    mImageView.setBackgroundDrawable(mBitmapDrawable);
    bt1.setOnClickListener(this);
  }
  @Override
  public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Intent mIntent = new Intent();
    mIntent.putExtra("image", buff);
    mIntent.setClass(this, activity2.class);
    startActivity(mIntent);
  }
  private byte[] Bitmap2Bytes(Bitmap bm){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
    return baos.toByteArray();
    }
}

第二個(gè)activity:

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
public class activity2 extends Activity {
  private Bitmap bitmap;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout2);
    ImageView mImageView = (ImageView) findViewById(R.id.image2);
    Intent mIntent = getIntent();
    byte buff[]=mIntent.getByteArrayExtra("image");
    bitmap = BitmapFactory.decodeByteArray(buff, 0, buff.length);
    BitmapDrawable mBitmapDrawable = new BitmapDrawable(bitmap);
    mImageView.setBackgroundDrawable(mBitmapDrawable);
  }
}

發(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相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android中HttpURLConnection類使用介紹

    Android中HttpURLConnection類使用介紹

    早些時(shí)候其實(shí)我們都習(xí)慣性使用HttpClient,但是后來Android6.0之后不再支持HttpClient,需要添加Apache的jar才行,所以,就有很多開發(fā)者放棄使用HttpClient了,HttpURLConnection畢竟是標(biāo)準(zhǔn)Java接口(java.net) ,適配性還是很強(qiáng)的
    2022-12-12
  • Android自定義Toolbar使用方法詳解

    Android自定義Toolbar使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Android自定義Toolbar使用方法 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Android端TCP長(zhǎng)連接的性能優(yōu)化教程分享

    Android端TCP長(zhǎng)連接的性能優(yōu)化教程分享

    在開發(fā)過程中,我們經(jīng)常會(huì)用到TCP/IP連接實(shí)現(xiàn)即時(shí)數(shù)據(jù)傳輸,下面這篇文章主要給大家介紹了關(guān)于Android端TCP長(zhǎng)連接的性能優(yōu)化的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2018-03-03
  • Android中使用GridView實(shí)現(xiàn)仿微信圖片上傳功能(附源代碼)

    Android中使用GridView實(shí)現(xiàn)仿微信圖片上傳功能(附源代碼)

    由于工作要求最近在使用GridView完成圖片的批量上傳功能,我的例子當(dāng)中包含仿微信圖片上傳、拍照、本地選擇、相片裁剪等功能,如果有需要的朋友可以看一下
    2017-08-08
  • Android中Textview超鏈接實(shí)現(xiàn)方式

    Android中Textview超鏈接實(shí)現(xiàn)方式

    TextView中的超鏈接可以通過幾種方式實(shí)現(xiàn):1.Html.fromHtml,2.Spannable,3.Linkify.addLinks。下面分別進(jìn)行測(cè)試,包括修改字體樣式,下劃線樣式,點(diǎn)擊事件等,需要的朋友可以參考下
    2016-02-02
  • android如何設(shè)置小區(qū)廣播默認(rèn)信道(50與60并支持雙卡)

    android如何設(shè)置小區(qū)廣播默認(rèn)信道(50與60并支持雙卡)

    置小區(qū)廣播默認(rèn)信道50與60,并支持雙卡主要是印度市場(chǎng),具體的實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈
    2013-06-06
  • Android?WindowManager深層理解view繪制實(shí)現(xiàn)流程

    Android?WindowManager深層理解view繪制實(shí)現(xiàn)流程

    WindowManager是Android中一個(gè)重要的Service,是全局且唯一的。WindowManager繼承自ViewManager。WindowManager主要用來管理窗口的一些狀態(tài)、屬性、view增加、刪除、更新、窗口順序、消息收集和處理等
    2022-11-11
  • Android Studio 合并module到統(tǒng)一文件夾的方法

    Android Studio 合并module到統(tǒng)一文件夾的方法

    這篇文章主要介紹了Android Studio 合并module到統(tǒng)一文件夾的方法,補(bǔ)充介紹了android studio關(guān)于同名資源文件的合并技巧,需要的朋友可以參考下
    2018-04-04
  • Android實(shí)現(xiàn)閱讀APP平移翻頁效果

    Android實(shí)現(xiàn)閱讀APP平移翻頁效果

    這篇文章主要介紹了Android實(shí)現(xiàn)閱讀APP平移翻頁效果的具體方法,模仿多看閱讀平移翻頁,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Android framework ATMS啟動(dòng)流程

    Android framework ATMS啟動(dòng)流程

    這篇文章主要為大家介紹了Android framework ATMS啟動(dòng)流程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03

最新評(píng)論

秦皇岛市| 无锡市| 遂川县| 贡觉县| 新疆| 洞口县| 留坝县| 花莲县| 留坝县| 南木林县| 明光市| 灵山县| 于田县| 芦溪县| 信宜市| 靖远县| 安平县| 双辽市| 吉安县| 象州县| 阳朔县| 邹城市| 桐城市| 靖宇县| 古交市| 西林县| 太和县| 景东| 盐源县| 胶州市| 嘉义市| 山西省| 郁南县| 宽城| 灯塔市| 鄂托克旗| 班玛县| 沈阳市| 从化市| 石泉县| 梨树县|