如何将选定的文件输入图像转换为 blob

我想使用文件输入来选择一些图像。在我的 HTML 代码中,我有这个

<input type="file" ref="file" name="images[]">

选择后,我想将每个选定的图像转换为一个斑点。我如何在我的 Vue 应用程序中实现这一目标?我不确定是否需要使用文件读取器,或者是否需要模拟 ajax 调用以将图像转换为 blob


慕雪6442864
浏览 115回答 1
1回答

慕盖茨4494581

const demoDonutOptions = {&nbsp; color: {&nbsp; &nbsp; scale: {&nbsp; &nbsp; &nbsp; java: "#FF0000",&nbsp; &nbsp; &nbsp; javascript: "#00FF00",&nbsp; &nbsp; &nbsp; "c++": "#0000FF"&nbsp; &nbsp; }&nbsp; },&nbsp; height: "300px"};请注意,需要指定所有组才能color.scale使此示例正常工作:import React from "react";import ReactDOM from "react-dom";import { DonutChart } from "@carbon/charts-react";import "@carbon/charts/styles.css";const colors = {&nbsp; java: "#FF0000",&nbsp; javascript: "#00FF00",&nbsp; "c++": "#0000FF"};const chartData = [&nbsp; {&nbsp; &nbsp; group: "java",&nbsp; &nbsp; value: 300&nbsp; },&nbsp; {&nbsp; &nbsp; group: "javascript",&nbsp; &nbsp; value: 600&nbsp; },&nbsp; {&nbsp; &nbsp; group: "c++",&nbsp; &nbsp; value: 200&nbsp; }];const demoDonutOptions = {&nbsp; color: {&nbsp; &nbsp; scale: colors&nbsp; },&nbsp; height: "300px"};function App() {&nbsp; return (&nbsp; &nbsp; <div className="App">&nbsp; &nbsp; &nbsp; <h3>React Donut chart with label</h3>&nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; &nbsp; <DonutChart data={chartData} options={demoDonutOptions} />&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div>&nbsp; );}const rootElement = document.getElementById("root");ReactDOM.render(<App />, rootElement);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript