<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() {
@Override
public 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() {
@Override
public 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();
}
}