2016-03-29 11 views
1

imageViewの画像を共有したいと思います。どのようにできるのか ?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
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")); 
関連する問題