Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
makePicture(){
// refresh page here
Camera.getPicture({
destinationType: Camera.DestinationType.FILE_URI,
targetWidth: 1000,
targetHeight: 1000
}).then((imageData) => {
// imageData is a base64 encoded string
// console.log(imageData);
// var img64 = "data:image/jpeg;base64," + imageData;
this.postFile(imageData);
}, (err) => {
console.log(err);
});
}
}
doCamera() {
Camera.getPicture(this.options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
// let base64Image = "data:image/jpeg;base64," + imageData;
this.uploadPhoto(imageData);
}, (err) => {
alert(err);
});
}
getPicture(){
alert("Get Picture Called");
let option = {
destinationType : Camera["DestinationType"].DATA_URL,
allowEdit : false,
targetWidth : 50
}
Camera.getPicture(option).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
//"data:image/jpeg;base64," +
let base64Image = imageData;
this.imageData = base64Image;
alert(base64Image);
}, (err) => {
});
}
selectPhoto(): void {
Camera.getPicture({
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
destinationType: Camera.DestinationType.DATA_URL,
quality: 100,
encodingType: Camera.EncodingType.PNG,
}).then(imageData => {
this.myPhoto = imageData;
this.uploadPhoto(this.myPhoto);
}, error => {
console.log("ERROR -> " + JSON.stringify(error));
});
}
takePhoto() {
Camera.getPicture({
destinationType: Camera.DestinationType.DATA_URL,
targetHeight: 500,
targetWidth: 500,
correctOrientation: true
}).then((imageData) => {
this.photos.push({ src: "data:image/jpeg;base64," + imageData, likes: 0 });
}, (err) => {
console.log(err);
});
}
takePicture(): void {
if (!this.platform.is('cordova')) {
return console.warn('Device must run cordova in order to take pictures');
}
Camera.getPicture().then((dataURI) => {
const blob = this.pictureService.convertDataURIToBlob(dataURI);
this.viewCtrl.dismiss({
messageType: MessageType.PICTURE,
selectedPicture: blob
});
});
}
.create((observer: Observer) => {
const cameraOptions: CameraOptions = {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
encodingType: Camera.EncodingType.JPEG,
correctOrientation: true,
};
this.setOptions(cameraOptions, options);
Camera.getPicture(cameraOptions)
.then((imageData) => {
observer.next(imageData);
observer.complete();
})
.catch(error => {
observer.error(this.getErrorMessage(error));
observer.complete();
});
});
}
openCamera(pictureSourceType: any) {
var self = this;
let options: CameraOptions = {
quality: 95,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: pictureSourceType,
encodingType: Camera.EncodingType.PNG,
targetWidth: 400,
targetHeight: 400,
saveToPhotoAlbum: true,
correctOrientation: true
};
Camera.getPicture(options).then(imageData => {
const b64toBlob = (b64Data, contentType = '', sliceSize = 512) => {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
camera () : void {
let options = {
targetWidth: 500,
destinationType: 0
};
Camera.getPicture(options)
.then(
(photo : any) => this.updateOutput('<img alt="" src="data:image/jpeg;base64,'+photo+'">'),
(error : string) => this.updateOutput(error, true)
);
}