代码之家  ›  专栏  ›  技术社区  ›  Steve

显示最后一张图片

  •  0
  • Steve  · 技术社区  · 14 年前

    嗨,我正在将相机中的图像(拍照)插入mediastore.images.media数据存储。

    有人知道我怎样才能展示最后一张照片吗?

    我使用uri image=contenturis.withAppendedID(externalContenturi,45);显示数据存储中的图像,但显然45不是正确的图像。

    我尝试将信息从上一个活动(相机)传递到显示活动,但我假设由于照片回拨是它自己的线程,所以值永远不会被设置。照片代码如下

    camera.pictureCallback photocallback=新建camera.pictureCallback()。{

        public void onPictureTaken(byte[] data, Camera camera) {
            // TODO Auto-generated method stub
            FileOutputStream fos;
            try
            {
                Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length);
                fileUrl = MediaStore.Images.Media.insertImage(getContentResolver(),  bm, "LastTaken", "Picture");
    
                if(fileUrl == null)
                {
                    Log.d("Still", "Image Insert Failed");
                    return;
                } else
                {
    
                     picUri = Uri.parse(fileUrl);
                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, picUri));
                }
            }
            catch(Exception e)
            {
                Log.d("Picture", "Error Picture: ", e);
            }
            camera.startPreview();
    
        }
    };
    
    1 回复  |  直到 11 年前
        1
  •  1
  •   Diego Torres Milano    14 年前

    你可以用这样的东西来获取最后拍摄的图像

        final ContentResolver cr = getContentResolver();
        final String[] p1 = new String[] {
                MediaStore.Images.ImageColumns._ID,
                MediaStore.Images.ImageColumns.DATE_TAKEN
        };
        Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null,
                p1[1] + " DESC");
    
        if ( c1.moveToFirst() ) {
            Log.d(TAG, "last picture (" + c1.getInt(0) + ") taken on: " +
                              new Date(c1.getLong(1));
        }
    
        c1.close();