使用本机裁剪图像 [英] Crop image with react-native

查看:89
本文介绍了使用本机裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello World,

Hello World,

我试图裁剪图像,例如在本机文档

I trying to crop an image like explain on the React-native Doc

<Image source={{uri: this.props.image, crop: {left: 50, top: 50, width: 100, height: 100}}} style={{height: 100, width: 100}}/>

但这不起作用,无法裁剪图像。

But it's doesn't work the image is not cropped.

有什么想法吗?

推荐答案

从文档中获取:


在基础架构方面,原因是它允许我们将元数据附加到该对象。例如,如果您使用的是require('./ my-icon.png'),那么我们会添加有关其实际位置和大小的信息(不要依赖这个事实,将来可能会改变!)。这也是将来的证明,例如,我们可能希望在某些时候支持sprites,而不是输出{uri:...},我们可以输出{uri:...,crop:{left:10,top:50,宽度:20,高度:40}},并透明地支持在所有现有呼叫站点上进行拼写。

On the infrastructure side, the reason is that it allows us to attach metadata to this object. For example if you are using require('./my-icon.png'), then we add information about its actual location and size (don't rely on this fact, it might change in the future!). This is also future proofing, for example we may want to support sprites at some point, instead of outputting {uri: ...}, we can output {uri: ..., crop: {left: 10, top: 50, width: 20, height: 40}} and transparently support spriting on all the existing call sites.

React Native Image当前不支持图像裁剪,至少不是您指定的方式,但是您仍然可以使用其他选项来完成相同的工作。

React Native Image is not currently supporting image cropping, at least not the way you pointed, however you still have other options that will do the same job.


  1. ImageEditor
    React Native Component,同样来自文档:




裁剪由URI参数指定的图像。如果URI指向远程
图像,它将自动下载。如果无法加载/下载
映像,则会调用失败回调。

Crop the image specified by the URI param. If URI points to a remote image, it will be downloaded automatically. If the image cannot be loaded/downloaded, the failure callback will be called.




  1. 裁剪不需要链接。

  2. 图像裁剪选择器另一个提供裁剪功能的软件包,但是另一种方式:拣货。需要链接,但值得庆幸的是,它还支持RN版本> 0.40。

  1. Cropping doesn't require linking.
  2. Image Crop Picker another package that offers cropping, but in a different way: Picking. Requires linking, but thankfully it also supports RN versions > 0.40.

我没有使用过任何一个,但是如果我是您,我将首先尝试使用图像编辑器,因为除了导入之外,您无需进行任何其他安装。

I haven't used any of them, but if I were you, I would first try Image Editor, since you don't need any additional installation except importing.

这篇关于使用本机裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆