How to fix preview Window and fab buttons of camera-preview? - ionic-framework

I am using the following code to make a camera-based app. But the preview window is not fixed and easily bud dragging over the screen it replaces. Also fab buttons are in behind of preview window. How is possible to fix them over each other on the screen.
home.ts
constructor(public navCtrl: NavController, private cameraPreview: CameraPreview) {
this.startCamera();
}
startCamera() {
const cameraPreviewOpts: CameraPreviewOptions = {
x: 40,
y: 40,
width: window.screen.width-1,
height: window.screen.height-1,
camera: 'rear',
tapPhoto: true,
previewDrag: true,
toBack: false,
alpha: 1
};
this.cameraPreview.startCamera(cameraPreviewOpts).then(
(res) => {
console.log(res);
},
(err) => {
console.log(err);
});
}
showCamera(){
this.cameraPreview.show();
}
stopCamera(){
this.cameraPreview.stopCamera();
}
takePicture(){
const pictureOpts: CameraPreviewPictureOptions = {
width: 1280,
height: 1280,
quality: 85
}
this.cameraPreview.takePicture(pictureOpts).then(function(imgData){
console.log('Picture taken');
(<HTMLInputElement>document.getElementById('previewPicture')).src = 'data:image/jpeg;base64,' + imgData;
}, (err) => {
console.log(err);
});
}
}
home.html:
<ion-content padding>
<ion-fab right bottom>
<button ion-fab color="primary" (click)="takePicture()">
<ion-icon name="md-camera"></ion-icon>
</button>
</ion-fab>
</ion-content>

Basically you need to "send" camera preview to back of the page and disable dragging option.
Try this:
const cameraPreviewOpts: CameraPreviewOptions = {
x: 40,
y: 40,
width: window.screen.width-1,
height: window.screen.height-1,
camera: 'rear',
tapPhoto: true,
previewDrag: false,
toBack: true,
alpha: 1
};
Your html code seems to be ok so your "fab" button should become visible.
If you want to use preview on whole screen- change width & height accordingly (remove -1) also,
x & y determine where your preview vindow will start, so set to 0 if you want to use it on whole screen.
Hope it helps!

Related

Ionic - Angular - Create botom modal / popup

I want to create a pop up under ionic that appears at the bottom and disappears when you click above it exactly like on the Youtube application when you click on the middle button.
How can i do that ?
This example image also shows well.
This is a possible solution :
// ------------------- TS CODE -----------------------------
constructor(public modalController: ModalController) {}
openBottomPopUp() {
this.modalController
.create(
{
component: PopUpPageToDisplayPage,
backdropDismiss: true,
swipeToClose: true,
cssClass: 'bottom-pop-up'
})
.then(modal => {
modal.present().then();
});
}
// ------------------- SCSS CODE -----------------------------
.bottom-modal {
.modal-wrapper {
width: 100%;
height: 35%;
position: absolute;
bottom: 0;
border-radius: 10% 10% 0 0;
}
.modal-shadow {
position: absolute;
height: 35%;
bottom: 0;
}
}
the modal-shadow must also be changed so that the pop up disappears when clicked outside. The height can be defined according to your needs.
PopUpPageToDisplayPage is the page you want to display in the popup.
You can use all parameters of ion-modal (https://ionicframework.com/docs/api/modal)
An Ionic implementation exists for this component through the ActionSheetController:
constructor(private actionSheetController: ActionSheetController) { }
async open() {
(await this.actionSheetController.create({
buttons: [
{text: 'item 1'},
{text: 'item 2'},
{text: 'item 3', handler: () => console.log('clicked')},
{text: 'cancel', role: 'cancel'},
]
})).present();
}

image selection des not work in ionic 2 app

i am trying to open the photolibrary of android to select images using ionic 2.
here is the code of the home.ts in witch the camera plugin is used.
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import {Camera} from '#ionic-native/camera';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
image640:any;
constructor(public navCtrl: NavController,public camera : Camera)
{
}
openGallery()
{
var options = {
quality: 100,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
saveToPhotoAlbum: true,
correctOrientation: true,
};
this.camera.getPicture(
options
).then(
(imageData)=>
{
this.image640 = 'data:image/jpeg;base64,'+imageData;
},
(err) =>
{
console.log(err);
}
);
}
}
And the code of the home.html is below :
<ion-header>
<ion-navbar>
<ion-title align="center">
Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<img src="image640" *ngIf="image640"/>
<Button align="center" ion-button (click)="openGallery()">Open
Gallery</Button>
</ion-content>
but when i click on the opengallery button, the android library is opened but when i select an image, a blank screen appear during about 8 seconds, and after that, the it is the rootpage that is displayed. Then i cannot see the selected image in my page.
can somebody help ?
Set options
var options = {
quality: 100,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
saveToPhotoAlbum: true,
correctOrientation: true,
};
Then select photos like this
this.camera.getPicture(options).then((imagePath) => {
// Special handling for Android library
if (this.platform.is('android') && sourceType ===
this.camera.PictureSourceType.PHOTOLIBRARY) { //when selecting from library
//your code goes here
} else { //when capturing by camera
//your code goes here
}

When applying lockSwipes, I cannot scroll image in X-axis

I am developing an app using ionic v1.
I placed ion-slide-page in ion-slides and ion-scroll in ion-slide-page as shown below. This ion-scroll contains an image.
What I want to do is to keep the slide from moving left and right when the image is enlarged. (Like Facebook)
If I enlarge the image, I cannot scroll the image in X-axis.
Template:
<ion-slides options="options" slider="data.slider">
<ion-slide-page ng-repeat="image in post.imgs">
<ion-scroll
direction="xy"
scrollbar-x="false" scrollbar-y="false"
zooming="true" min-zoom="1" max_zoom="3"
overflow-scroll="false" locking="false" has-bouncing="true"
style="width: 100%; height: 100%" class="vertical-center"
delegate-handle="scrollHandle{{$index}}"
on-release="updateSlideStatus()">
<image style="width: 100%; height: 100%" ng-src="{{image}}"></image>
</ion-scroll>
</ion-slide-page>
</ion-slides>
Contorller:
$scope.$on("$ionicSlides.sliderInitialized", function(event, data){
console.log('ionic slides initialized');
$scope.slider = data.slider;
$scope.activeIndex = 0;
$scope.isSwipeLocked = false;
});
$scope.$on("$ionicSlides.slideChangeStart", function(event, data){
console.log('Slide change is beginning');
});
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
console.log('ionic slides change end');
$scope.activeIndex = data.slider.activeIndex;
$scope.previousIndex = data.slider.previousIndex;
});
$scope.updateSlideStatus = function() {
var zoom = $ionicScrollDelegate.$getByHandle('scrollHandle' + $scope.activeIndex).getScrollPosition().zoom;
if (zoom === 1) {
if ($scope.isSwipeLocked == true) {
$scope.slider.unlockSwipes();
$scope.isSwipeLocked = false;
}
} else {
if ($scope.isSwipeLocked == false) {
$scope.slider.lockSwipes();
$scope.isSwipeLocked = true;
}
}
};
Is there any idea?

How to add "Follow the link popup" into TinyMCE 4

I implemented somethink like on this picture:
if you click on a link popup will appear and you can follow the link.
jQuery(function($){
/**
* add the follow link popup to all TinyMCE instances
*/
if (!window.tinymce) return;
tinymce.on('AddEditor', function( event ) {
tinymce.editors.forEach(function(editor) {
if (!editor.isFollowLinkAdded) {
editor.isFollowLinkAdded = true;
editor.on('blur', function(e) {
jQuery(e.target.contentDocument.body).find('#followLink').remove();
});
editor.on('click', function(e) {
var link = jQuery(e.target).closest('a');
jQuery(e.view.document.body).find('#followLink').remove();
if (link.length) {
e.preventDefault();
var POPUP_WIDTH = 215,
isRightSide = (jQuery(e.view.document).width()-e.pageX) >= POPUP_WIDTH,
boxCss = {
top: e.pageY,
padding: '6px 10px',
position: 'absolute',
backgroundColor: '#ffffff',
border: '1px solid #a8a8a8',
borderRadius: '2px',
boxShadow: '0 1px 3px rgba(0, 0, 0, 0.2)',
color: '#666666',
cursor: 'pointer',
whiteSpace: 'nowrap',
zIndex: 502
};
boxCss[(isRightSide) ? 'left' : 'right'] = (isRightSide) ? e.pageX : jQuery(e.view.document).width()-e.pageX;
jQuery('<a/>', {
href: link.attr('href'),
text: link.attr('href'),
target: '_blank'
}).css({
cursor: 'pointer',
display: 'inline-block',
maxWidth: '100px',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}).wrap(
jQuery('<p/>', {
text: 'Click to follow: ',
id: 'followLink',
}).on('click', function(){
var win = window.open(link.attr('href'), '_blank');
win.focus();
}).css(boxCss)
).parent().appendTo(e.view.document.body);
}
});
}
});
}, true );
});
The most recent version of TinyMCE 4 (4.5.3) includes the option to open a link in the right click menu of the editor - no need to write your own custom code.

Show multiple image at one page taken from Camera with Ionic Native in Ionic 2

I am trying to show images one after another at the same page taken from camera in ionic 2 but I am only able to show one images on the page.
Here is my code:
public base64Image: string;
public CompleteImage: Array<{image:string}>;
public OpenCamera() {
Camera.getPicture({
quality: 75,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 200,
targetHeight: 200,
saveToPhotoAlbum: false
}).then(imageData => {
alert(1);
this.base64Image = "data:image/jpeg;base64," + imageData;
alert(2);
this.CompleteImage.push(this.base64Image);
alert(this.CompleteImage.length);
}, error => {
console.log("ERROR -> " + JSON.stringify(error));
});
}
for front end
if I am using this code
<ion-card *ngIf="base64Image">
<img [src]="base64Image" />
</ion-card>
then it is showing image but from collection. If I am trying to show it
<ion-card *ngFor="let i of CompleteImage">
<img [src]="i.image"/>
</ion-card>
then it is not working.
Here is the link from where I'm trying to achieve this. here
You should Ideally be using the ImagePicker API which can be obtained by importing ImagePicker from 'ionic-native' library.
import { Camera, ImagePicker } from 'ionic-native';
Have a function like this in a helper class (if you prefer)
export function pickImages() {
const options = {
quality: 50,
width: 1366,
height: 768,
maximumImagesCount: 10,
};
return ImagePicker.getPictures(options);
}
The above function will return a promise. You can use it like this.
pickImages().then((results) => {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
}
}, (err) => { });
Keep in mind this will return the location strings of images. You'll have to read this some other way
Reference
https://ionicframework.com/docs/v2/native/image-picker/