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 に答える