首页 文章

在reactjs中剪切图像

提问于
浏览
0

在,我想裁剪一个图像,像它应该是在1048像素宽度和280像素高度的视图,如下所示,

例如:给出一个1048像素宽280像素高的图像,接下来我要裁剪它以在所有帖子侧具有3:4的宽高比 . 如下

得到的图像很好,有1048px和280px,但在所有帖子上都是blury . 如上 . 我正在使用reactJS与typescript和react-easy-crop库来裁剪图像 .

这是代码

interface Iprops{
setLargeSize?: {
        width: number;
        height: number;
    };
}

if (props.setAspect != null) {
        // Set Aspect is provided so use that
        aspectWidth = props.setAspect.width;
        aspectHeight = props.setAspect.height;
    }
    else if (props.setSize != null) {
        // Set Size is provided so use that & override any other settings
        aspectWidth = props.setSize.width;
        aspectHeight = props.setSize.height;
    }
    else if (props.setLargeSize != null){
        aspectWidth = props.setLargeSize.width;
        aspectHeight = props.setLargeSize.height;
    }

Private load() {
    aspectWidth: this.props.setSize != null || this.props.setAspect || this.props.setLargeSize != null ? this.state.aspectWidth : aspect.width,
    aspectHeight: this.props.setSize != null || this.props.setAspect || this.props.setLargeSize != null ? this.state.aspectHeight : aspect.height 
};

请帮我设置正确的图像和指导 .

1 回答

  • 0

    你可以在这里使用svg概念..如果你通过svg标签渲染你的图像 . 然后,您可以动态/手动设置高度和宽度 .

    <svg width="10" height="10">
      <rect x="0" y="0" width="10" height="10" fill="blue" />
    </svg>
    

    这只是一个例子 . 你可以像这样使用你的图像 .

相关问题