PhotoViewer是常用的Cordova Plugin之一,用來顯示圖片。
組件特性:
- 根據Url顯示圖片
- 支持手勢,可放大縮小
- 帶分享按鈕,可分享圖片
- 帶關閉按鈕
- 加載錯誤時自動關閉組件
- 支持Base64
參考地址:https://github.com/sarriaroman/photoviewer
========================================================================
1)安裝插件和包:
ionic cordova plugin add com-sarriaroman-photoviewer
npm install --save @ionic-native/photo-viewer
2)添加插件到app.module.ts:
import { PhotoViewer } from '@ionic-native/photo-viewer';
別忘了
providers:[] 里面加上PhotoViewer;
3)在需要使用的地方:
import { PhotoViewer } from '@ionic-native/photo-viewer';
構造器中:private photoViewer: PhotoViewer
具體使用方法:
this.photoViewer.show('https://images2015.cnblogs.com/news/24442/201705/24442-20170502163240086-1545306933.jpg', '示例圖片');
效果圖:

如果不是暫時網絡圖片,而是相機拍攝的圖片,可以:
this.photoViewer.show(this.base64Image, '示例圖片');
base64Image參看camera插件。