通过控制器从服务中检索屏幕截图

时间:2016-02-04 12:40:17

标签: javascript angularjs cordova ionic-framework screenshot

我想用cordova-screenshot-plugin截取屏幕截图。我可以将该图片保存为变量或其他东西,以便我以后可以使用它吗?截屏服务:

xcodebuild: error: SDK "Debug-iphonesimulator" cannot be located.
xcodebuild: error: SDK "Debug-iphoneos" cannot be located.
fatal error: lipo: can't open input file: /Users/xxxxxxxx/build/Release-iphonesimulator/ABCFramework (No such file or directory)
cp: /Users/xxxxxxxx/build//build/Release-iphoneos/include/ABCFramework: No such file or directory

我将尝试使用按钮截取屏幕截图,并使用弹出窗口显示。

1 个答案:

答案 0 :(得分:0)

Cordova-Plugin-Screenshot API为您提供图片的文件路径。可以从智能手机的任何位置访问此文件路径。因此,您可以使用官方github存储库中提供的示例服务,并在控制器中使用类似的服务:

// app is define elsewhere in your application

app.controller('Awesome.Controller', AwesomeController);

AwesomeController.$inject = ['$cordovaScreenshot'];

function AwesomeController($cordovaScreenshot) {
  var vm = this;
  vm.onClick = takeScreenshot;

  function takeScreenshot() {
    $cordovaScreeshot.capture('mypic', 'jpg', 80).then(function(filepath) {
      vm.filepath = filepath;
    }
  }
}

使用这样的HTML模板:

<button on-click="vm.onClick()">take screenshot</button>

<div ng-if="vm.filepath">
  <p>Result: {{vm.filepath}}</p>
  <img ng-src="{{vm.filepath}}>
</div>