捕获的图像未显示在图库中,但已成功存储在 sdcard 中 [英] Captured image was not showing in gallery but it stored successfully in sdcard

查看:29
本文介绍了捕获的图像未显示在图库中,但已成功存储在 sdcard 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 android 开发的新手,我正在做一个小应用程序来使用 UVCCamera 捕获 USB Camrea 图像.

I am new to android development, i am doing small application to capture USB Camrea image using UVCCamera.

我使用 UVCCamera 捕获图像并像这样存储在 sdcard 中

I have captured image using UVCCamera and stored in sdcard like this

File filepath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "IMG_"+getDateTime() + ".jpg");
mCameraClient.captureStill(filepath.toString()); 

这里 mCameraClient 将与 UVC Camera 进行交互并捕获图像并存储在该路径中,它将回调 onCaptureDone 方法

here mCameraClient will intract with UVC Camera and capture image and store in that path and it will callback method onCaptureDone

@Override
        public void onCaptureDone(final String path) {
            // TODO Auto-generated method stub
            Log.e(TAG, "onCaptureDone  called");
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    //Toast -- Images Saved.
                }
            });
        }
    };

然后我从图像按钮调用图库 onClickListener

Then i am invoking gallery from an image button onClickListener

    private MediaScannerConnection conn;

File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM));
    File[] mImagefile = folder.listFiles(new FilenameFilter() {
                    public boolean accept(File dir, String filename) {

                            return filename.endsWith(".jpg");
                    }
                });

                if (mImagefile.length > 0) {

                    SCAN_PATH = folder.toString() + "/"
                            + mImagefile[mImagefile.length -1].getName();
                    Log.e(TAG, "SCAN PATH = " + SCAN_PATH);

                    if (conn != null) {
                        conn.disconnect();
                    }

                    conn = new MediaScannerConnection(this, this);
                    conn.connect();
                } else {
                    //Toast -- No Images Available
                }

如果过滤成功.

    @Override
    public void onMediaScannerConnected() {
        // TODO Auto-generated method stub
        Log.e(TAG, "onMediaScannerConnected");
        ;
        conn.scanFile(SCAN_PATH, null);
    }

    @Override
    public void onScanCompleted(String path, Uri uri) {
        // TODO Auto-generated method stub
        try {
            Log.e(TAG, "OnCompleted  path = " + path);
            if (uri != null) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(uri);
                startActivity(intent);
            }
        } finally {
            Log.e(TAG, "OnCompleted Disconnecting");
            conn.disconnect();
            conn = null;
        }
    }

这里我的问题是在图库中所有捕获的图像都没有显示.

Here my problem was in gallery all captured images was not displaying.

并且我已经检查了保存的目录,所有图像都已成功存储.[图像没有损坏,我已经验证]

And i have checked in saved directory, there all images was stored successfully.[Images was not corrupted, i have verified]

而且我已经检查了默认图库应用程序,因为这些图像也没有显示.

And i have checked in default gallery application, in that also those images was not displaying.

请帮我解决这个问题.

编辑 1:

我观察到一件事,当我捕获并保存图像时,它没有显示在图库中,但经过 2-3 小时后它出现在图库中.我想知道为什么会这样?

I have observed one thing, when i capture and saved image, it not showing in gallery but after some time like 2-3Hrs its was appearing in gallery. I WANT TO KNOW WHY LIKE THIS HAPPENING?

谢谢

推荐答案

拍完一张图片并保存到 sd 卡后,把这行代码放上.

Put this line of code after capture an image and save it to sd card.

File image_path="your image path";
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(image_path)));

这里image_path是保存图片文件的路径

Here image_path is saved image file's path

希望这对你有帮助..!

Hope this helps you..!

这篇关于捕获的图像未显示在图库中,但已成功存储在 sdcard 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆