我如何分享ImageView的图像?

时间:2016-03-29 13:36:54

标签: android image imageview share

我想分享imageView的图像。我能怎么做 ?

Button share=(Button)findViewById(R.id.button4); 
final int[] images={
    R.drawable.ic_launcher,
    R.drawable.st1,
    R.drawable.st2};
btn4.setOnClickListener(new View.OnClickListener() { 
    @Override public void onClick(View v) { 
        Intent localIntent1 = new Intent("android.intent.ACTION_SEND");
        localIntent1.setType("image/png");
        localIntent1.putExtra("android.intent.EXTRA_STREAM", Uri1);
        startActivity(Intent.createChooser(localIntent1, "Share"));
    });

...

1 个答案:

答案 0 :(得分:1)

View content = findViewById(R.id.full_image_view);
content.setDrawingCacheEnabled(true);

Bitmap bitmap = content.getDrawingCache();
File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg");
try {
       cachePath.createNewFile();
       FileOutputStream ostream = new FileOutputStream(cachePath);
       bitmap.compress(CompressFormat.JPEG, 100, ostream);
       ostream.close();
 } catch (Exception e) {
       e.printStackTrace();
 }

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(cachePath));
startActivity(Intent.createChooser(share,"Share via"));