相机功能不显示图像

Camera Functionality Not displaying Image

本文关键字:显示图 图像 显示 功能 相机      更新时间:2023-09-26

我有一个混合应用程序,它打开android的本机摄像头。我的代码:

public class CameraFunActivity extends Activity {  
    OpenCamera openCamera;  
   /** Called when the activity is first created. */
   @Override
    public void onCreate(Bundle savedInstanceState) {  
       super.onCreate(savedInstanceState);    
       setContentView(R.layout.main);    
     WebView webView=(WebView)findView  ById(R.id.webkitWebView1);  
     WebSettings settings = webView.getSettings();  
     settings.setJavaScriptEnabled(true);  
     settings.setDatabaseEnabled(true); 
      openCamera=new OpenCamera(webView,CameraFunActivity.this);  
         webView.addJavascriptInterface(openCamera,"camera");
    }  
   @Override   
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode== 0 && resultCode == Activity.RESULT_OK){ 
         System.out.println("!!!!!!!!!!!!!!!!!!!!Camera Working...........");
         String imagePath =  "file:/"+openCamera.getPath();
        System.out.println("Image Pathhhhhhhhhh :::::::::::: " + imagePath);
        openCamera.setPath(imagePath); 

. .}

HTML:函数captureImage1 () {camera.startCamera ();var path="file://" + camera.getPath();//警报(路径);. getelementbyid("image1").src =路径;}

public OpenCamera (WebView appView,Activity context) {
这一点。mAppView = appView;
this.context =上下文;}

public void setPath(String path){
    _path=path;
}
public String getPath(){
    return _path;
}
public void setBitmap(Bitmap bitmap){
    System.out.println("setting bitmap");
    this.bitmap=bitmap;
}
public Bitmap getBitmap(){
    System.out.println("getting bitmap");
    return bitmap;
}
public void startCamera(){
    /*
    Camera camera = Camera.open();
    Camera.Parameters parameters = camera.getParameters();
    parameters.setPictureFormat(PixelFormat.JPEG);
    camera.setParameters(parameters);*/
    Date dt = new Date();   
    int date=dt.getDate();
    int hours = dt.getHours();   
    int minutes = dt.getMinutes(); 
    int seconds = dt.getSeconds();   
    String curTime = date+"_"+hours + "_"+minutes + "_"+ seconds;
    _path=Environment.getExternalStorageDirectory() +"/"+curTime+".jpg";
    File file = new File( _path );
    Uri outputFileUri = Uri.fromFile( file );
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
    intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );


//  System.out.println("Paramssssssssssssss  " + camera.getParameters().toString());
    context.startActivityForResult(intent,0);

有时在img标签src显示图像,有时不显示。需要帮助才能找出问题所在。

还有,这和方向改变有关吗??

谢谢

我是这样解决的:

添加:
函数openCamera1 () {
result = camera. startcameraactivity ();

path1 = camera.getImagePath1 ();路径= " file://"+ path1;做{

fileIndicator = camera.findEOF ();}, (! fileIndicator)
. getelementbyid("image1").src =路径;
}

在OpenCamera中添加一个方法:

public boolean findEOF(){  
       File file=new File(imagePath1);  
       System.out.println("Inisde EOFL::::::::::::::"+file.length());  
        if(file.length()>0){ 
           System.out.println("Inisde length is::::::::::::::"+file.length());  
            return true;
      }         
       return false;
   }  

问题是在图像写入文件

之前调用了getimagepath ()