2

通过这种方式

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, REQUEST_CODE);

我在onActivityResult中得到了一个位图表单意图,而不是路径!,通过这种方式

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(intent, REQUEST_CODE);

我可以从意图中获取路径,而不是位图!!,如何从 android 相机获取位图(缩略图)和路径?

4

2 回答 2

4

从中您可以获取图像路径,使用该路径创建这样的缩略图

/**
 * 
 * Returns the given size of the bitmap
 * 
 * @param path
 * @return {@link Bitmap}
 */
private Bitmap getThumbnailBitmap(String path, int thumbnailSize) {
    BitmapFactory.Options bounds = new BitmapFactory.Options();
    bounds.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, bounds);
    if ((bounds.outWidth == -1) || (bounds.outHeight == -1)) {
        return null;
    }
    int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
            : bounds.outWidth;
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = originalSize / thumbnailSize;
    return BitmapFactory.decodeFile(path, opts);
}

给大小你想要多少

于 2013-08-12T09:25:23.080 回答
0

试试这个代码,我在一个应用程序中使用过它,这将完美运行,

static final int CAMERA_REQUEST = 1888;
String name =   dateToString(new Date(),"yyyy-MM-dd-hh-mm-ss");
File destination = new File(Environment.getExternalStorageDirectory(), name + ".jpg");
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
destination = new File(Environment.getExternalStorageDirectory(), name + ".jpg");
startActivityForResult(cameraIntent, CAMERA_REQUEST);

在你的 OnActivityResult()

Bundle bundle = data.getExtras();
    if(bundle != null){
    if (requestCode == CAMERA_REQUEST) { 
       Bitmap photo = (Bitmap) data.getExtras().get("data");

       //Here photo is your bitmap image, use this as per your requirement
于 2013-08-12T09:41:03.023 回答