热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Ionic3-ios-在屏幕上显示所选图像

如何解决《Ionic3-ios-在屏幕上显示所选图像》经验,为你挑选了1个好方法。

我设置了相机插件以从照片库中选择图像并使用以下代码将其上传到服务器:

getImage() {
  //By default the camera retrieves the image as a JPEG file.
  const options: CameraOptiOns= {
    quality: 100,
    destinationType: this.camera.DestinationType.FILE_URI,
    sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
    targetWidth:1080,
    targetHeight:1080,
    correctOrientation: true,
    mediaType: this.camera.MediaType.PICTURE,
    encodingType: this.camera.EncodingType.JPEG

  }

  this.camera.getPicture(options).then((fileUri) => {

    if (this.platform.is('ios')) {
        return this.crop.crop(fileUri, {quality: 100});
      } else if (this.platform.is('android')) {
        // Modify fileUri format, may not always be necessary
        fileUri = 'file://' + fileUri;

        /* Using cordova-plugin-crop starts here */
        return this.crop.crop(fileUri, { quality: 100 });
      }
  }, (err) => {
    console.log(err);

  }).then((path) => {
    // path looks like 'file:///storage/emulated/0/Android/data/com.foo.bar/cache/1477008080626-cropped.jpg?1477008106566'
    console.log('Cropped Image Path!: ' + path);
    this.imagePath = path;
    return path;
  });
}

然后,我在屏幕上显示我的图像预览,如下所示:


在iOS和Android上,选择图像,裁剪和上传工作都非常好.但是,在iOS上显示图像不起作用.(什么都没有显示)

我的控制台日志显示以下内容:

2017-12-07 15:06:52.559614-0500 fd-app [2537:1186586] [MC] systemgroup.com.apple.configurationprofiles路径的系统组容器是/private/var/containers/Shared/SystemGroup/systemgroup.com .apple.configurationprofiles 2017-12-07 15:06:52.560425-0500 fd-app [2537:1186586] [MC]从公共有效用户设置中读取.2017-12-07 15:06:55.754175-0500 fd-app [2537:1186662] [发现]发现扩展时遇到的错误:错误Domain = PlugInKit Code = 13"查询已取消"UserInfo = {NSLocalizedDescription =查询已取消} 2017- 12-07 15:07:04.589982-0500 fd-app [2537:1186586]裁剪图像路径!:file:/// var/mobile/Containers/Data/Application/8B2CD0E8-F6AC-4530-BF02-D2F7A188EAC2/tmp/cdv_photo_004.jpg

我尝试将照片库使用情况属性添加到Info.plist文件,但这没有帮助.有什么建议接下来要尝试什么?

更新:不确定这是否与它有关,但我使用的是Xcode 9.2 beta,因为我的iPhone是11.2

此外,一切我使用Google所指向的事实,这是一个权限问题,但是,选择图像后,图像出现在栽跟头......这使我怀疑一些奇怪的是怎么回事?裁剪器如何显示图像而不显示HTML页面?



1> Suraj Rao..:

如果您正在使用WKWebview这是在IOS 11默认的WebView按照官方的博客文章,你需要重写的file://使用你的HTML之前网址.

如果您正在使用本地文件(文本文件,图像,视频),则需要确保文件路径前面没有file://.

import { normalizeURL } from 'ionic-angular';

在你的功能中,

 this.imagePath = normalizeURL(path);
    return path;

进一步检查故障排除部分,说明相同.


推荐阅读
author-avatar
落幕YL他
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有