在Custom View Camera Preview Ionic 3中获取图片 [英] Get picture in Custom View Camera Preview Ionic 3

查看:204
本文介绍了在Custom View Camera Preview Ionic 3中获取图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我尝试使用 Camera Preview从自定义视图获取图片,但结果是图片始终为原始尺寸。这是我的代码。

  RunCamera(){

让Quarter = window.screen.height / 4,中=季度+(季度/ 2)
const cameraPreviewOpts:CameraPreviewOptions = {
x:0,
y:this.mid,
width:window.screen.width,
高度:70,
摄像头:'后方',
点击照片:true,
预览拖动:true,
返回:true,
alpha:1
}

//启动摄像头
this.cameraPreview.startCamera(cameraPreviewOpts)。然后(
(res)=> {
console.log( startCamera ok,res)
},
(err)=> {
console.log( startCamera Err,err)
});}

相机将像波纹管一样运行..运行良好。.



这是我的代码。

  takePic(){

/ /图片选项
const pictureOpts:CameraPreviewPictureOptions = {
宽度:1280,
高度:1280,
质量:85
}

/ /拍照
this.cameraPreview.takePicture(pictureOpts).then((imageData)=> {
console.log( takePicture,imageData);
this.selectedImage =‘data:image / png; base64,’+ imageData;

this.cameraPreview.stopCamera();
},(err)=> {
console.log(err);
alert(拍照时发生错误: + JSON.stringify(err))
});}

总有办法实现我的目标吗?

解决方案

最后5天,我无法自由拍照时选择尺寸。每个设备都有一组固定的可用尺寸。只有这些是可能的。如果我尝试使用上述选项拍照,则插件会选择与给定选项最接近的supportSize。



我想要的只是其中一部分图片。因此,您随后需要处理图像。



https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview/issues/440


Currently i try to get picture from custom view with Camera Preview, but the result is picture always original size. here my code..

RunCamera() {

let quarter = window.screen.height / 4, mid = quarter + (quarter/2)
const cameraPreviewOpts: CameraPreviewOptions = {
  x: 0,
  y: this.mid,
  width: window.screen.width,
  height: 70,
  camera: 'rear',
  tapPhoto: true,
  previewDrag: true,
  toBack: true,
  alpha: 1
}

// start camera
this.cameraPreview.startCamera(cameraPreviewOpts).then(
  (res) => {
    console.log("startCamera ok",res)
  },
  (err) => {
    console.log("startCamera Err",err)
  });}

Camera will run like bellow.. this run well..

after this, i need to take picture, but the result is like this..

Here my code..

takePic(){

// picture options
const pictureOpts: CameraPreviewPictureOptions = {
  width: 1280,
  height: 1280,
  quality: 85
}

// take a picture
this.cameraPreview.takePicture(pictureOpts).then((imageData) => {
  console.log("takePicture",imageData);
  this.selectedImage = 'data:image/png;base64,' + imageData;

  this.cameraPreview.stopCamera();
}, (err) => {
  console.log(err);
  alert("Error occured while taking picture:"+JSON.stringify(err))
});}

There is anyway to get my goal ?

解决方案

Finnaly after 5 days, i cannot freely choose the dimensions when taking a picture. Each device has a fixed set of possible dimensions that can be used. Only these are possible. If i try to take a picture with the options above, the plugin chooses a supportedSize that's closest to the given options.

What i want to have is just a part of the image. So you will need to manipulate the image afterwards. Manipulating images should not be part of this plugin.

https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview/issues/440

这篇关于在Custom View Camera Preview Ionic 3中获取图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆