【问题标题】:How to create custom camera in PhoneGap?如何在 PhoneGap 中创建自定义摄像头?
【发布时间】:2013-09-10 10:04:54
【问题描述】:

我正在为 Phonegap 和 jQuery mobile 做一个 android 和 iOS 应用程序。我想做一个类似的应用程序 这个应用程序:https://play.google.com/store/apps/details?id=jp.co.supersoftware.mangacamera&hl=vi

现在我遇到了自定义相机的问题。你帮我吗?或提出类似的解决方案。

感谢提前

【问题讨论】:

    标签: cordova camera


    【解决方案1】:

    我写了一个tutorial 来介绍如何为 iOS 构建一个自定义摄像头作为 PhoneGap 插件。它归结为 JavaScript 中这样的表达式:

    cordova.exec(function(){
        console.log("success", arguments);
    }, function(){
        console.log("failure", arguments);
    }, "CustomCamera", "openCamera", []);
    

    这实质上是在 Objective-C 中调用[CustomCamera openCamera:command]。你只需要创建一个CustomCamera 类扩展CDVPlugin 并实现一个openCamera 方法。

    iOS 中的主要相机接口是UIImagePickerController。在 openCamera 方法中,您可以将 UIImagePickerController 作为模态视图打开。 UIImagePickerController 有一个委托方法,当图片被捕捉时调用。在这个委托方法中,你需要做这样的事情:

    [self.commandDelegate
        sendPluginResult:[CDVPluginResult
            resultWithStatus:CDVCommandStatus_OK
            messageAsString:imagePath]
        callbackId:self.latestCommand.callbackId];
    

    其中self.latestCommand 是对传递给openCameracommand 参数的引用。这将调用cordova.exec 中的成功函数(第一个参数)。

    请注意,为了使其正常工作,您需要将以下内容添加到config.xml

    <feature name="CustomCamera">
        <param name="ios-package" value="CustomCamera" />
    </feature>
    

    希望有帮助!

    【讨论】:

      【解决方案2】:

      希望我能正确理解您的问题,并且您希望自定义 phonegap 附带的相机插件。

      在这种情况下,请按照Cordova Camera Docs 上的说明进行操作。可选参数cameraOptions 确实为您带来了很多配置相机的可能性。

      如果这些可能性不足以满足您的目的,您可能需要下载相机插件的源代码并更改插件本身。这需要更多的时间和精力。但是,如果您想这样做,这些链接可能会对您有所帮助:

      【讨论】:

      • 谢谢米维斯。我试试..如果成功我会回复你的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      相关资源
      最近更新 更多