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