如何将位图作为PNG保存到Gallery中的特定文件夹?

时间:2016-11-30 20:34:47

标签: android file-io bitmap filesystems gallery

鉴于我想要保存到手机公共图库中特殊文件夹的位图,我尝试了这个:

public static void saveToGallery(Context context, Bitmap bitmap) {
    File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), File.separator + "FolderForMyApp");
    path.mkdirs();
    File imageFile = new File(path, "image_name.png");
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
    }
    catch (IOException e) {
        Log.w(TAG, "Could not resolve file stream: " + e);
    }
}

然而它实际上并没有出现在画廊中。我做错了什么?

1 个答案:

答案 0 :(得分:0)

它不会出现在图库中,因为您必须刷新图库,因此它知道新文件

var query = "select SID, age from Students where Name=\'Jason\'" + String.fromCharCode(10) +
            "order by age asc";
$.ajax({
    url: "http://mywebserver/query",
    data: {
        env: "dbserver1",
        endTime: "getUTCDate()",
        startTime: "dateadd(hour, -336, getUTCDate())",
        text: query
    },
    type: "GET",
    dataType: "json"
}).done(function (datum) {
});

嘲笑格式化。我在手机上。