生活随笔
收集整理的這篇文章主要介紹了
android生成将布局生成海报保存并分享
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<uses
-permission android
:name
="android.permission.WRITE_EXTERNAL_STORAGE" /><uses
-permission android
:name
="android.permission.READ_EXTERNAL_STORAGE" />
*** 生成海報
*/private void getShareImg() {mViewBind
.shareImgLayout
.rlSharePanert
.setDrawingCacheEnabled(true);mViewBind
.shareImgLayout
.rlSharePanert
.buildDrawingCache();mHandler
.postDelayed(new Runnable() {@Overridepublic void run() {Bitmap bitmap
= mViewBind
.shareImgLayout
.rlSharePanert
.getDrawingCache();if (bitmap
== null
) {bitmap
= Bitmap
.createBitmap(mViewBind
.shareImgLayout
.rlSharePanert
.getWidth(),mViewBind
.shareImgLayout
.rlSharePanert
.getHeight(), Bitmap
.Config
.ARGB_8888
);Canvas canvas
= new Canvas(bitmap
);if (Build
.VERSION
.SDK_INT
>= 11) {mViewBind
.shareImgLayout
.rlSharePanert
.measure(View
.MeasureSpec
.makeMeasureSpec(mViewBind
.shareImgLayout
.rlSharePanert
.getWidth(),View
.MeasureSpec
.EXACTLY
), View
.MeasureSpec
.makeMeasureSpec(mViewBind
.shareImgLayout
.rlSharePanert
.getHeight(), View
.MeasureSpec
.EXACTLY
));mViewBind
.shareImgLayout
.rlSharePanert
.layout((int) mViewBind
.shareImgLayout
.rlSharePanert
.getX(),(int) mViewBind
.shareImgLayout
.rlSharePanert
.getY(),(int) mViewBind
.shareImgLayout
.rlSharePanert
.getX() + mViewBind
.shareImgLayout
.rlSharePanert
.getMeasuredWidth(),(int) mViewBind
.shareImgLayout
.rlSharePanert
.getY() + mViewBind
.shareImgLayout
.rlSharePanert
.getMeasuredHeight());} else {mViewBind
.shareImgLayout
.rlSharePanert
.measure(View
.MeasureSpec
.makeMeasureSpec(0, View
.MeasureSpec
.UNSPECIFIED
),View
.MeasureSpec
.makeMeasureSpec(0, View
.MeasureSpec
.UNSPECIFIED
));mViewBind
.shareImgLayout
.rlSharePanert
.layout(0, 0, mViewBind
.shareImgLayout
.rlSharePanert
.getMeasuredWidth(),mViewBind
.shareImgLayout
.rlSharePanert
.getMeasuredHeight());}mViewBind
.shareImgLayout
.rlSharePanert
.draw(canvas
);}savePicture(bitmap
, "qufuusershare.jpg");mViewBind
.shareImgLayout
.rlSharePanert
.destroyDrawingCache(); }}, 1000);}
public void savePicture(Bitmap bm
, String fileName
) {if (null
== bm
) {return;}File foder
= new File(Environment
.getExternalStorageDirectory().getAbsolutePath() + "/qufuuser");if (!foder
.exists()) {foder
.mkdirs();}File myCaptureFile
= new File(foder
, fileName
);try {if (!myCaptureFile
.exists()) {myCaptureFile
.createNewFile();}BufferedOutputStream bos
= new BufferedOutputStream(new FileOutputStream(myCaptureFile
));bm
.compress(Bitmap
.CompressFormat
.JPEG
, 90, bos
);bos
.flush();bos
.close();showToast("截圖以保存到\n系統相冊");final UMImage image
= new UMImage(mContext
, myCaptureFile
);image
.setThumb(new UMImage(mContext
, myCaptureFile
));ShareBottomDialog
.getInstance().setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView
<?> parent
, View view
, int position
, long id
) {if (umShareHelper
!= null
) {if (position
== 0) {umShareHelper
.shareWeixin(mActivity
, image
);} else if (position
== 1) {umShareHelper
.shareWeixinCircle(mActivity
, image
);}}}}).initView((FragmentActivity
) mActivity
, false);} catch (IOException e
) {e
.printStackTrace();}}
總結
以上是生活随笔為你收集整理的android生成将布局生成海报保存并分享的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。