【问题标题】:Camera Functionality Not displaying Image相机功能不显示图像
【发布时间】:2012-01-27 22:54:42
【问题描述】:

我有一个混合应用程序,可以打开安卓的原生相机。 我的代码:

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(); //警报(路径); document.getElementById("image1").src=path; }

public OpenCamera (WebView appView,Activity context) {
this.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 处显示图像,有时则不会。需要帮助找出问题。

另外,它与方向变化有关吗?

谢谢

【问题讨论】:

    标签: javascript android html camera


    【解决方案1】:

    我是这样解决的:

    添加:
    函数 openCamera1(){
    结果 = camera.startCameraActivity1();
    path1=camera.getImagePath1();
    path="file://"+path1; 做{
    fileIndicator=camera.findEOF();
    }while(!fileIndicator)
    document.getElementById("image1").src=path;
    }

    并在 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;
    
       }  
    

    所以问题是在将图像写入文件之前调用了 get imagePath()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 2021-02-26
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多