我想在客户端使用 JavaScript 调整图像大小。我找到了两种解决方案,一种是使用.toDataURL()函数,另一种是使用.toBlob()函数。两种解决方案都有效。好吧,我只是好奇这两个功能之间有什么区别?哪一个更好?或者我应该什么时候使用.toDataURL()函数或.toBlob()函数?
这是我用来输出这两个函数的代码,图像大小(字节)和图像颜色(我不确定这个)略有不同。代码有问题吗?
<html>
<head>
<title>Php code compress the image</title>
</head>
<body>
<input id="file" type="file" onchange="fileInfo();"><br>
<div>
<h3>Original Image</h3>
<img id="source_image"/>
<button onclick="resizeImage()">Resize Image</button>
<button onclick="compressImage()">Compress Image</button>
<h1 id="source_image_size"></h1>
</div>
<div>
<h3>Resized Image</h3>
<h1> image from dataURL function </h1>
<img id="result_resize_image_dataURL"/>
<h1> image from toBlob function </h1>
<img id="result_resize_image_toBlob"/>
</div>
<div>
<fieldset>
<legend>Console output</legend>
<div id='console_out'></div>
</fieldset>
</div>
<script>
//Console logging (html)
if (!window.console)
console = {};
var console_out = document.getElementById('console_out'); …Run Code Online (Sandbox Code Playgroud) 如何获得反应组件的高度?我想使用一个组件的高度值作为其他组件的填充值,如何在React Native中做到这一点?例如,我制作了一个选择器组件
import { Picker } from '@react-native-picker/picker';
Run Code Online (Sandbox Code Playgroud)
我想做一个<view>带有padding值的组件padding:{Picker}.height,怎么做?
更新
感谢 @Aseem Gautam 和 @Aniket Kolekar,我已经尝试了 Picker 组件的解决方案,但它不起作用,当我使用 View 组件尝试它时,它工作得很好。为什么会发生这种情况?这是否意味着 Picker 组件不继承 View props?这是我尝试过的代码
import React, { Component } from "react";
import { View, Text, SectionList } from "react-native";
import { Picker } from "@react-native-picker/picker";
export default class App extends Component {
find_dimension(layout){
const {x, y, width, height} = layout;
console.warn(x);
console.warn(y);
console.warn(width);
console.warn(height);
}
render(){
return(
<View>
<Picker onLayout={(event) => {this.find_dimension(event.nativeEvent.layout)}}>
<Picker.Item label="Java" value="java" /> …Run Code Online (Sandbox Code Playgroud)