【问题标题】:it says "no thumbnail" after the image is saved in to gallery- android bitmap图像保存到画廊后,它说“没有缩略图” - android位图
【发布时间】:2016-09-20 23:15:38
【问题描述】:

我有点击方法将图像保存到画廊。单击“保存”后,文件夹在图库中创建,但是当我进入图库时,它显示“没有缩略图”... 这是我的代码:

 String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
                File myDir = new File(root + "/PhotoEditor ");
                myDir.mkdirs();
                Random generator = new Random();
                int n = 10000;
                n = generator.nextInt(n);
                String fname = "Image-" + n + ".jpg";
                File file = new File(myDir, fname);
                if (file.exists())
                    file.delete();
                try {
                    FileOutputStream out = new FileOutputStream(file);
                    if (sb != null) {
                        sb.compress(Bitmap.CompressFormat.JPEG, 90, out);
                    }
                    out.flush();
                    out.close();
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
                Toast.makeText(ShowPhotoActivity.this,"Your image is saved to gallery",Toast.LENGTH_LONG).show();


                // Tell the media scanner about the new file so that it is
                // immediately available to the user.
                MediaScannerConnection.scanFile(ShowPhotoActivity.this, new String[] { file.toString() }, null,
                        new MediaScannerConnection.OnScanCompletedListener() {
                            public void onScanCompleted(String path, Uri uri) {
                                Log.i("ExternalStorage", "Scanned " + path + ":");
                                Log.i("ExternalStorage", "-> uri=" + uri);
                            }
                        });

【问题讨论】:

    标签: android bitmap android-gallery android-bitmap


    【解决方案1】:

    你能记录“file.toString()”然后看看你得到了什么吗?您可能需要传递绝对路径: file.getAbsolutePath() 而不是调用 file.toString() 但它很难诊断。关闭流后,您是否使用文件管理器应用确认 jpg 确实存在?

    【讨论】:

    • 是的,我认为它没有获取位图。你能给我看个代码吗?
    猜你喜欢
    • 2012-01-23
    • 2018-04-25
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多