0

指定したサイズの画像をSDカードの希望の場所に保存しようとしています。intent.putExtraを使用して、デフォルトのカメラアプリケーションを介して画像を撮影しています。

ここにコードがあります

public void onClick(View v) {
    //Setting up the URI for the desired location
    imageFile = "bmp"+v.getId()+".png";
    File f = new File (folder,imageFile);
    imageUri = Uri.fromFile(f);

    //Setting the desired size parameters
    private Camera mCamera;      
    Camera.Parameters parameters = mCamera.getParameters();
    parameters.setPreviewSize(width, height);
    mCamera.setParameters(parameters);       

    //Passing intent.PutExtras to defaul camera activity
    Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(i,CAMERA_PIC_REQUEST);   
}




@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
    return;
}

画像撮影後、カメラ起動力が閉じます。この方法で、デフォルトのカメラアクティビティによって撮影された画像のサイズを変更することは可能ですか?

または別のカメラアプリケーションが必要ですか?

4

1 に答える 1

0

画像がファイルとして保存されている場合は、そのファイルからビットマップを作成し、このメソッドを使用してサイズを小さくし、このビットマップをアクティビティに渡します。

public static Bitmap decodeFile(File file, int requiredSize) {
    try {

        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(file), null, o);

        // The new size we want to scale to

        // Find the correct scale value. It should be the power of 2.
        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp / 2 < requiredSize
                    || height_tmp / 2 < requiredSize)
                break;
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        return BitmapFactory.decodeStream(new FileInputStream(file), null,
                o2);
    } catch (FileNotFoundException e) {
    }
    return null;
}
于 2012-09-02T08:27:53.140 に答える