2016-03-29 12 views
1

imageView öğesinin resmini paylaşmak istiyorum. Nasıl yapabilirim ?ImageView'ın resmini nasıl paylaşabilirim?

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")); 
    }); 

....

cevap

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")); 
İlgili konular