欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)合并生成分享圖片功能

 更新時(shí)間:2019年03月26日 15:51:58   作者:Chaek  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)合并生成分享圖片功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

有時(shí)候分享功能都是很需要分享一個(gè)當(dāng)前屏幕的界面的截圖因,以前做校內(nèi)APP的時(shí)候用到過(guò),拿出來(lái)分享分享, 用以前寫(xiě)過(guò)的自定義課表軟件。

Android 自定義View課程表表格

看到的是圖片只顯示到11節(jié)處,下面的沒(méi)有顯示到 所以用到的 ScrollView

因此截圖節(jié)截取ScrollView View的圖片

一、首先計(jì)算出整個(gè)ScrollView 的高度寬度生成對(duì)應(yīng)大小的的Bitmap 然后把使用Canvas 將ScrollView 的界面繪制上去

// 獲取ScrollView 實(shí)際高度
 h = 0;
 for (int i = 0; i < scrollView.getChildCount(); i++) {
  h += scrollView.getChildAt(i).getHeight();
  scrollView.getChildAt(i).setBackgroundResource(android.R.color.white);
 }
 // 創(chuàng)建對(duì)應(yīng)大小的bitmap
 Bitmap bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.ARGB_8888);
 Canvas canvas = new Canvas(bitmap);
 scrollView.draw(canvas);

二、獲取分享的頭部和底部圖片的Bitmap

// BitmapFactory.decodeResource函數(shù)直接轉(zhuǎn)換資源文件為Bitmap 

 Bitmap head = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.share_term_table_header);
 Bitmap foot = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.share_term_table_footer);

三、合并頭部底部和界面View的截圖

if (head == null) {
  return null;
 }
 int headWidth = head.getWidth();
 int kebianwidth = kebiao.getWidth();
 int fotwid = san.getWidth();

 int headHeight = head.getHeight();
 int kebiaoheight = kebiao.getHeight();
 int footerheight = san.getHeight();
 //生成三個(gè)圖片合并大小的Bitmap
 Bitmap newbmp = Bitmap.createBitmap(kebianwidth, headHeight + kebiaoheight + footerheight, Bitmap.Config.ARGB_8888);
 Canvas cv = new Canvas(newbmp);
 cv.drawBitmap(head, 0, 0, null);// 在 0,0坐標(biāo)開(kāi)始畫(huà)入headBitmap

 //因?yàn)槭謾C(jī)不同圖片的大小的可能小了 就繪制白色的界面填充剩下的界面
 if (headWidth < kebianwidth) {
  System.out.println("繪制頭");
  Bitmap ne = Bitmap.createBitmap(kebianwidth - headWidth, headHeight, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(ne);
  canvas.drawColor(Color.WHITE);
  cv.drawBitmap(ne, headWidth, 0, null);
 }
 cv.drawBitmap(kebiao, 0, headHeight, null);// 在 0,headHeight坐標(biāo)開(kāi)始填充課表的Bitmap
 cv.drawBitmap(san, 0, headHeight + kebiaoheight, null);// 在 0,headHeight + kebiaoheight坐標(biāo)開(kāi)始填充課表的Bitmap
 //因?yàn)槭謾C(jī)不同圖片的大小的可能小了 就繪制白色的界面填充剩下的界面
 if (fotwid < kebianwidth) {
  System.out.println("繪制");
  Bitmap ne = Bitmap.createBitmap(kebianwidth - fotwid, footerheight, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(ne);
  canvas.drawColor(Color.WHITE);
  cv.drawBitmap(ne, fotwid, headHeight + kebiaoheight, null);
 }
 cv.save(Canvas.ALL_SAVE_FLAG);// 保存
 cv.restore();// 存儲(chǔ)
 //回收
 head.recycle();
 kebiao.recycle();
 san.recycle();

下載地址

環(huán)境Android Studio

csdn下載地址

查看GIT

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論