Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将相机拍摄的图像设置为ImageButton背景_Android_Imagebutton - Fatal编程技术网

Android 将相机拍摄的图像设置为ImageButton背景

Android 将相机拍摄的图像设置为ImageButton背景,android,imagebutton,Android,Imagebutton,我正在从相机拍摄照片,希望将其设置为ImageButton背景的背景 拍摄照片,在ImageView中展示,并将其保存到设备中,完整的路径非常有效 如果有问题,以下是我在OnActivityResult中的处理代码: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Handling the photo ImageView imageView=(Ima

我正在从相机拍摄照片,希望将其设置为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);
    }
}

看到完整的例子,这将有助于你。我所有的代码已经工作100%,我需要的是显示我捕获的图像上的一个按钮。