Java Android定制相机预览?

Java Android定制相机预览?,java,android,camera,android-camera,Java,Android,Camera,Android Camera,我正在为android创建一个camera应用程序。 我想要我的相机预览活动,如下图(例如)。我想将我的相机预览活动分为四个或多个部分 也就是说,在我从相机中单击一张图片后,当我返回到我的(相机图像预览活动)活动时,我希望将活动屏幕分为四个或更多部分,每个部分都应该有该预览图像 原因是我想用imagerender script效果来试验每个预览[但这个解决方案超出了我的问题范围,因为我知道如何使用render scripts],而且每个部分都应该有单独的渲染 有谁能帮我找到解决办法吗 这将是一

我正在为
android
创建一个
camera
应用程序。 我想要我的
相机预览
活动,如下图(例如)。我想将我的
相机预览
活动分为四个或多个部分

也就是说,在我从
相机
中单击一张图片后,当我返回到我的(相机图像预览活动)
活动
时,我希望将活动
屏幕
分为四个或更多部分,每个部分都应该有该
预览图像

原因是我想用image
render script
效果来试验每个预览[但这个解决方案超出了我的问题范围,因为我知道如何使用render scripts],而且每个部分都应该有单独的
渲染

有谁能帮我找到解决办法吗

这将是一个很大的帮助,如果有任何例子或教程为这一点


提前谢谢。

经过努力,我找到了解决办法。是啊

camera.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <FrameLayout 
        android:id="@+id/preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    </FrameLayout>
    <LinearLayout
        android:id="@+id/imageViewLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="gone"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/img1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/ic_launcher" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/img2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/ic_launcher" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/img3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/ic_launcher" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/img4"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/ic_launcher" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <Button
        android:id="@+id/clickButton"
        style="@android:style/Animation.Translucent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/click" />

</RelativeLayout>
您的onPictureTaken()应该如下所示:

/**
     * This will be called after taking picture from camera.
     */
    final transient private PictureCallback mPicture = new PictureCallback() {
        /**
         * After taking picture, onPictureTaken() will be called where image
         * will be saved.
         * 
         */
        @Override
        public void onPictureTaken(final byte[] data, final Camera camera) {
            OutputStream outStream = null;
            try {
                outStream = new BufferedOutputStream(new FileOutputStream(
                        mGetFile));
                outStream.write(data); // Write the data to corresponding place.
                ((FrameLayout) findViewById(R.id.preview))
                        .setVisibility(View.GONE);
                ((LinearLayout) findViewById(R.id.imageViewLayout))
                        .setVisibility(View.VISIBLE);
                final Options options = new Options();
                options.inScaled = true;
                options.inPurgeable = true;

                // to scale the image to 1/8
                options.inSampleSize = 8;

                Bitmap imageBitmap = BitmapFactory.decodeByteArray(data, 0,
                        data.length, options);
                ImageView image1 = (ImageView) findViewById(R.id.img1);
                ImageView image2 = (ImageView) findViewById(R.id.img2);
                ImageView image3 = (ImageView) findViewById(R.id.img3);
                ImageView image4 = (ImageView) findViewById(R.id.img4);

                image1.setImageBitmap(imageBitmap);
                image2.setImageBitmap(imageBitmap);
                image3.setImageBitmap(imageBitmap);
                image4.setImageBitmap(imageBitmap);
            } catch (FileNotFoundException e) {
                camera.release();
            } catch (IOException e) {
                camera.release();
            } finally {
                try {
                    outStream.close();

                } catch (IOException e) {
                    camera.release();
                } 
            }
        }
    };
这将显示您上面提到的捕获图像


谢谢:)

经过努力,我找到了解决办法。是啊

camera.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <FrameLayout 
        android:id="@+id/preview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    </FrameLayout>
    <LinearLayout
        android:id="@+id/imageViewLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="gone"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/img1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/ic_launcher" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/img2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/ic_launcher" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/img3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/ic_launcher" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/img4"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/ic_launcher" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <Button
        android:id="@+id/clickButton"
        style="@android:style/Animation.Translucent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="@string/click" />

</RelativeLayout>
您的onPictureTaken()应该如下所示:

/**
     * This will be called after taking picture from camera.
     */
    final transient private PictureCallback mPicture = new PictureCallback() {
        /**
         * After taking picture, onPictureTaken() will be called where image
         * will be saved.
         * 
         */
        @Override
        public void onPictureTaken(final byte[] data, final Camera camera) {
            OutputStream outStream = null;
            try {
                outStream = new BufferedOutputStream(new FileOutputStream(
                        mGetFile));
                outStream.write(data); // Write the data to corresponding place.
                ((FrameLayout) findViewById(R.id.preview))
                        .setVisibility(View.GONE);
                ((LinearLayout) findViewById(R.id.imageViewLayout))
                        .setVisibility(View.VISIBLE);
                final Options options = new Options();
                options.inScaled = true;
                options.inPurgeable = true;

                // to scale the image to 1/8
                options.inSampleSize = 8;

                Bitmap imageBitmap = BitmapFactory.decodeByteArray(data, 0,
                        data.length, options);
                ImageView image1 = (ImageView) findViewById(R.id.img1);
                ImageView image2 = (ImageView) findViewById(R.id.img2);
                ImageView image3 = (ImageView) findViewById(R.id.img3);
                ImageView image4 = (ImageView) findViewById(R.id.img4);

                image1.setImageBitmap(imageBitmap);
                image2.setImageBitmap(imageBitmap);
                image3.setImageBitmap(imageBitmap);
                image4.setImageBitmap(imageBitmap);
            } catch (FileNotFoundException e) {
                camera.release();
            } catch (IOException e) {
                camera.release();
            } finally {
                try {
                    outStream.close();

                } catch (IOException e) {
                    camera.release();
                } 
            }
        }
    };
这将显示您上面提到的捕获图像


谢谢:)

单击这四个部分后,您希望看到什么?我希望预览在相机表面分为四个部分,并在使用此效果拍摄照片时保存。您希望单击这四个部分时看到什么?我希望预览在相机表面分为四个部分,并在使用此效果拍摄照片时保存。此处,如果您希望预览的图像超过4个,那么最好使用GridLayout,因为管理线性布局有点复杂。在这里,如果您希望预览的图像超过4个,那么最好使用GridLayout,因为管理线性布局有点复杂。