首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在android图库中保存图片

如何在android图库中保存图片
EN

Stack Overflow用户
提问于 2013-12-31 23:35:59
回答 6查看 80.8K关注 0票数 25

我尝试将图像保存到WathsappIMG中,但当我转到图片库android时,我看不到图像,并且可以从ES文件资源管理器中看到目录中的图像

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

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

     // Retrieve the image from the res folder
        BitmapDrawable drawable = (BitmapDrawable) principal.getDrawable();
        Bitmap bitmap1 = drawable.getBitmap();

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

        try {

            output = new FileOutputStream(file);

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

        }

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

回答 6

Stack Overflow用户

发布于 2015-01-28 13:31:39

以下是您在要将图片保存到图库时应输入的内容

MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle , yourDescription);

该代码将在图库的末尾添加图像。因此,请检查您的画廊图片,以确保

票数 11
EN

Stack Overflow用户

发布于 2013-12-31 23:49:21

尝试添加以下内容:

MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle , yourDescription);

填写yourBitmap、yourTitle和yourDescription的详细信息,或者将其保留为""

票数 7
EN

Stack Overflow用户

发布于 2018-07-26 22:14:04

对于Xamarin研究员:

public static void SaveToTheGalley(this string filePath, Context context)
{
    var values = new ContentValues();
    values.Put(MediaStore.Images.Media.InterfaceConsts.DateTaken, Java.Lang.JavaSystem.CurrentTimeMillis());
    values.Put(MediaStore.Images.Media.InterfaceConsts.MimeType, "image/jpeg");
    values.Put(MediaStore.MediaColumns.Data, filePath);
    context.ContentResolver.Insert(MediaStore.Images.Media.ExternalContentUri, values);
}

别忘了android.permission.WRITE_EXTERNAL_STORAGE权限。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20859584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档