0

我正在从相机拍摄照片,并想将其设置为 ImageButton 背景的背景。

拍照,将其呈现在 ImageView 中并将其保存到设备以及完整的路径效果很好。

如果有问题,这是我在 OnActivityResult 中的处理代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Handling the photo

    ImageView imageView=(ImageView)findViewById(R.id.imageView1);
    if (requestCode == TAKE_A_PHOTO) {
        // Check if the result includes a thumbnail Bitmap
        if (data != null) {
            if (data.hasExtra("data")) {
                Bitmap thumbnail=data.getParcelableExtra("data");
                imageView.setImageBitmap(thumbnail);
            }
        } else {
            // If there is no thumbnail image data, the image
            // will have been stored in the target output URI.
            // Resize the full image to fit in out image view.
            int width = imageView.getWidth();
            int height = imageView.getHeight();
            BitmapFactory.Options factoryOptions = new BitmapFactory.Options();
            factoryOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(outputFileUri.getPath(),
                    factoryOptions);
            int imageWidth = factoryOptions.outWidth; int imageHeight = factoryOptions.outHeight;
            // Determine how much to scale down the image
            int scaleFactor = Math.min(imageWidth/width, imageHeight/height);
            // Decode the image file into a Bitmap sized to fill the View
            factoryOptions.inJustDecodeBounds = false; factoryOptions.inSampleSize = scaleFactor; factoryOptions.inPurgeable = true;
            Bitmap bitmap = BitmapFactory.decodeFile(outputFileUri.getPath(),
                    factoryOptions);
            imageView.setImageBitmap(bitmap);
            Toast.makeText(this, "Image saved to "+ incomePhotoURL, Toast.LENGTH_LONG).show();

        }
    }
    else if (requestCode == LOAD_AN_IMAGE) {
        Uri selectedImageUri=data.getData();
        isAudioRecordPath=idanUtils.getRealPathFromURI(selectedImageUri, AddIncome.this);
        Toast.makeText(this, "Image loaded from "+incomePhotoURL, Toast.LENGTH_LONG).show();
        Log.i(ItemsDataBase.TAG, "Image loaded from "+incomePhotoURL);
    }
}
4

0 回答 0