如何使用Intent从ImageView Android Share保存Gif文件

时间:2017-10-09 11:45:48

标签: android

我在imageview中显示来自url的gif图像及其工作正常。现在我想使用共享意图共享此gif文件但不使用其共享简单图像而不是gif。

  protected void shareIntent() {

    Bitmap bitmap;
    OutputStream output;
    img.setDrawingCacheEnabled(true);
    // Retrieve the image from the res folder
    bitmap = img.getDrawingCache();

    // Find the SD Card path
    File filepath = Environment.getExternalStorageDirectory();

    // Create a new folder AndroidBegin in SD Card
    File dir = new File(filepath.getAbsolutePath() + "/Share Image/");
    dir.mkdirs();

    // Create a name for the saved image
    File file = new File(dir, "sample_wallpaper.gif");

    try {

        // Share Intent
        Intent share = new Intent(Intent.ACTION_SEND);

        // Type of file to share
        share.setType("image/gif");

        output = new FileOutputStream(file);

        // Compress into png format image from 0% - 100%
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
        output.flush();
        output.close();

        // Locate the image to Share
        Uri uri = Uri.fromFile(file);

        // Pass the image into an Intnet
        share.putExtra(Intent.EXTRA_STREAM, uri);

        // Show the social share chooser list
        startActivity(Intent.createChooser(share, "Share Image "));

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

请帮助................

0 个答案:

没有答案