|
public class How2CaptureScreenAndShareIt { |
|
|
|
private void draw(float scaleW, float scaleH) { |
|
File dest = AndroidUtils.getTmpFile(); |
|
FileOutputStream fos = null; |
|
try { |
|
final Bitmap bmp = |
|
createBitmap((int) (mRoot.getWidth() * scaleW), (int) (mRoot.getHeight() * scaleH), |
|
Bitmap.Config.RGB_565); |
|
Canvas canvas = new Canvas(bmp); |
|
canvas.scale(scaleW, scaleH); |
|
mRoot.draw(canvas); |
|
|
|
fos = new FileOutputStream(dest); |
|
bmp.compress(Bitmap.CompressFormat.JPEG, 80, fos); |
|
bmp.recycle(); |
|
fos.flush(); |
|
|
|
MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), |
|
dest.getAbsolutePath(), App.getAccountUser().getNickname() + "行程规划", null); |
|
getActivity().sendBroadcast( |
|
new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(dest))); |
|
Toost.message(getActivity().getString(R.string.picture_saved_to_storage, "相册")); |
|
|
|
// 直接分享行程规划截图 |
|
Intent intent = new Intent(Intent.ACTION_SEND); |
|
intent.setType("image/jpg"); |
|
Uri uri = Uri.fromFile(dest); |
|
intent.putExtra(Intent.EXTRA_STREAM, uri); |
|
intent.putExtra(Intent.EXTRA_SUBJECT, "行程规划"); |
|
intent.putExtra(Intent.EXTRA_TEXT, "行程规划"); |
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
startActivity(Intent.createChooser(intent, "分享至")); |
|
} catch (OutOfMemoryError e) { |
|
Ln.e(e); |
|
draw(scaleW * 0.9f, scaleH * 0.9f); |
|
} catch (FileNotFoundException e) { |
|
Ln.e(e); |
|
Toost.message("保存失败"); |
|
} catch (IOException e) { |
|
Ln.e(e); |
|
Toost.message("保存失败"); |
|
} finally { |
|
IoUtils.safeClose(fos); |
|
} |
|
} |
|
} |