在android中单独的相机类

时间:2014-06-10 11:40:41

标签: android camera

此类调用单击照片的相机类,但在此类的活动结果上,它在第41行上显示错误。

package com.example.fish;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.ImageView;
import com.non_activity.*;

public class Camera  extends Activity
{
    ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //setContentView(R.layout.name_image);

        image=(ImageView)findViewById(R.id.cameraImage);

        Intent in= new Intent(this,com.camera.CameraCall.class);
        startActivityForResult(in, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
                if (requestCode == 1) 
                {
                    ImageRotation ri= new ImageRotation();
                                               image.setImageBitmap(ri.getImageOrientation(com.camera.Camera_nonClass.getPath(), 7));   //line 41
                }

    }


}

这是实际的相机代码应用程序,实际上是从相机点击照片 并将结果返回给调用camra类。

package com.camera;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;

public class CameraCall extends Activity
{
    final private int CAPTURE_IMAGE = 1;
    String imgPath=null;

    @Override
     protected void onCreate(Bundle savedInstanceState) 
     {
         super.onCreate(savedInstanceState);
         cameraCheck();
     }

    private  void cameraCheck()
    {
        Context context=CameraCall.this;
        PackageManager packageManager = context.getPackageManager();

        if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) 
        {
            //yes
            captureImage(); 
        }else{
            //no
            finish();
        }
    }



     /******************************************** Camera Function Implementation*******************************************/ 
    /*
     * Capturing Camera Image will lauch camera app requrest image capture
     */
    private void captureImage()
    {
        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, setImageUri());
        startActivityForResult(intent, CAPTURE_IMAGE);
    }


    public Uri setImageUri() 
    {
        File mediaFile=null;
        File mediaStorageDir = new File("/sdcard/Fish/");
        if (mediaStorageDir.exists()==false) 
        {
            Boolean b=mediaStorageDir.mkdirs();
            if(b==false)
                return null;
        }
        if(mediaStorageDir.exists()==true)
        {
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.getDefault()).format(new Date());
            mediaFile = new File(mediaStorageDir.getPath() + File.separator+ "IMG_" + timeStamp + ".PNG");
        }

        Uri imgUri = Uri.fromFile(mediaFile);
        this.imgPath = mediaFile.getAbsolutePath();
        com.camera.Camera_nonClass.setPath(this.imgPath);
        Log.e("image path  1122:-", this.imgPath+"");
        return imgUri;
    }

    public String getImagePath() 
    {
        return imgPath;
    }


    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
        if (resultCode != Activity.RESULT_CANCELED) 
        {
            if (requestCode == CAPTURE_IMAGE) 
            {
                com.camera.Camera_nonClass.setPath(getImagePath());
                Log.e("image path  11:-",com.camera.Camera_nonClass.getPath()+"");
                finish();
            }
            {
                super.onActivityResult(requestCode, resultCode, data);
            }
        }

    }
}

这是存储从camra获取的图像路径的文件。

package com.camera;

public class Camera_nonClass 
{
     static String path;

    public static String getPath() {
        return path;
    }

    public static void setPath(String path) {
        Camera_nonClass.path = path;
    }

}

0 个答案:

没有答案