ionic3 使用相机

2018-05-28  本文已影响0人  南京确善能
ionic cordova plugin add cordova-plugin-camera
npm install --save @ionic-native/camera
import { Camera, CameraOptions } from '@ionic-native/camera';

/**
 * 原生相机
 */
@Injectable()
export class CameraProvider {

  constructor(public http: HttpClient, private camera: Camera) {
    
  }
  /**
   * 调起相机
   */
  cameraClick():Promise<any>{
    const options: CameraOptions = {
      quality: 50,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    }
    return new Promise((resolve, reject) => {
      this.camera.getPicture(options).then((imageData) => { 
        resolve('data:image/jpeg;base64,' + imageData);
      }, (err) => {
        reject(err)
      });
    });
   
  }

}

相机返回的是base64

上一篇下一篇

猜你喜欢

热点阅读