Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.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 将图像另存为两个图层的组合_Android_Camera_Imageview_Frame_Surfaceview - Fatal编程技术网

Android 将图像另存为两个图层的组合

Android 将图像另存为两个图层的组合,android,camera,imageview,frame,surfaceview,Android,Camera,Imageview,Frame,Surfaceview,我正在尝试制作一个带有自定义帧的相机应用程序。我的布局如下 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout

我正在尝试制作一个带有自定义帧的相机应用程序。我的布局如下

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <!-- Place the objects you want on the bottom here -->

    <SurfaceView
        android:id="@+id/surface01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <!-- Objects that should be on top of the SurfaceView -->

    <ImageView
        android:id="@+id/pictureFrame"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/frame" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/controls"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerVertical="true"
        android:orientation="horizontal"
        android:weightSum="5" >
        <LinearLayout
            android:layout_width="0dp"
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>

        <Button
            android:id="@+id/btnFrame"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Change Frame" />

        <Button
            android:id="@+id/btnSnap"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Take Photo" />
    </LinearLayout>
</RelativeLayout>
public class MainActivity extends Activity implements SurfaceHolder.Callback {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        snap = (Button) findViewById(R.id.btnSnap);
        snap.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO take a photo, combine the Frame Layer with the camera
                // preview to produce a single jpeg. Once a photo has been
                // taken, show it to the user and give them sharing options
                camera.takePicture(myShutterCallback,  myPictureCallback_RAW, myPictureCallback_JPG);

            }
        });

    }
    ShutterCallback myShutterCallback = new ShutterCallback(){

        @Override
        public void onShutter() {
            // TODO Auto-generated method stub

        }

    };
    PictureCallback myPictureCallback_RAW = new PictureCallback(){

        @Override
        public void onPictureTaken(byte[] arg0, Camera arg1) {
            // TODO Auto-generated method stub

        }

    };
    PictureCallback myPictureCallback_JPG = new PictureCallback(){

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            Bitmap bitmapPicture=BitmapFactory.decodeByteArray(data, 0, data.length);
            Uri uriTarget= getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());
            OutputStream imageFileOS;
            try{
                imageFileOS=getContentResolver().openOutputStream(uriTarget);
                imageFileOS.write(data);
                imageFileOS.flush();
                imageFileOS.close();
                Toast.makeText(getApplicationContext(),
                        "Image saved: " + uriTarget.toString(),
                        Toast.LENGTH_LONG).show();
            }catch(FileNotFoundException e){
                e.printStackTrace();
            }catch(IOException e){
                e.printStackTrace();
            }
            camera.startPreview();

        }

    };

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
                               int height) {
        if(previewing){
            camera.stopPreview();
            previewing=false;
        }

        if(camera!=null){
            try{
                camera.setPreviewDisplay(surfaceHolder);
                camera.startPreview();
                previewing=true;
            }catch(IOException e){
                e.printStackTrace();
            }
        }

    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        camera=Camera.open();

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        camera.stopPreview();
        camera.release();
        camera=null;
        previewing=false;
    }
}

目前,我只能保存surfaceview中没有框架的内容。是否可以将图像保存为SurfaceView和ImageView的组合?任何帮助都将不胜感激。

表面视图似乎正在接收预览,但捕获的相机图像将作为JPEG数据到达。所以SurfaceView的内容并不重要。你能把接收到的相机图像渲染成位图,在上面渲染你在ImageView中拥有的任何东西,然后保存结果吗?@genius你完成任务了吗,或者找到问题的解决方案了吗?