在此花费大量时间后:
检查是否已授予权限。 然后:
步骤1:在活动中创建想要的图像的ImageView,然后将其转换为无位图
ImageView imageView = findViewById(R.id.image);Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();//save the image now:saveImage(bitmap);//share itsend();
步骤2:将图片存储在内部文件夹中:
private static void saveImage(Bitmap finalBitmap) { String root = Environment.getExternalStorageDirectory().getAbsolutePath(); File myDir = new File(root + "/saved_images"); Log.i("Directory", "==" + myDir); myDir.mkdirs(); String fname = "Image-test" + ".jpg"; File file = new File(myDir, fname); if (file.exists()) file.delete(); try { FileOutputStream out = new FileOutputStream(file); finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); }}步骤3:传送储存的图片:
public void send() { try { File myFile = new File("/storage/emulated/0/saved_images/Image-test.jpg"); MimeTypeMap mime = MimeTypeMap.getSingleton(); String ext = myFile.getName().substring(myFile.getName().lastIndexOf(".") + 1); String type = mime.getMimeTypeFromExtension(ext); Intent sharingIntent = new Intent("android.intent.action.SEND"); sharingIntent.setType(type); sharingIntent.putExtra("android.intent.extra.STREAM", Uri.fromFile(myFile)); startActivity(Intent.createChooser(sharingIntent, "Share using")); } catch (Exception e) { Toast.makeText(getbaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); }}现在,发送后,如果您不想在存储中保存图像,可以将其删除。检查其他链接可以做到这一点。



