程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何从 image::ImageBuffer 到 actix_web::HttpResponse大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何从 image::ImageBuffer 到 actix_web::httpResponse?

开发过程中遇到如何从 image::ImageBuffer 到 actix_web::httpResponse的问题如何解决?下面主要结合日常开发的经验,给出你关于如何从 image::ImageBuffer 到 actix_web::httpResponse的解决方法建议,希望对你解决如何从 image::ImageBuffer 到 actix_web::httpResponse有所启发或帮助;

目标是使用板条箱 initialValues 生成二维码,并立即将其作为 import { Form,input,button,Space } from "antd"; import { MinusCircLeoutlined,PlusOutlined } from "@ant-design/icons"; import React from "react"; //Basic IDea /* I want the user to be able to edit some details of a purchase order that already exists in the database,then resubmit the order with a form. The details of the purchase order should be orginally displayed in the form input fIElds,and the user can change them directly via those fIElds. */ //This is the order that already exists const order = { po_number: "123abc",carrIEr: "Fastway",items: [ { item_code: "dnh75n",quantity: "10",special_requirements: "Add picture of happy dog" },{ item_code: "456def",quantity: "4",special_requirements: "Do not include lIDs" } ] }; const GroupForm = () => { const onFinish = (values) => { console.log(values); }; //Create form fIElds based off how many items are in the order const iteminputs = order.items.map((item) => { return { item_code: item.item_code,quantity: item.quantity,special_requirements: item.special_requirements }; }); return ( <div> <Form onFinish={onFinish}> <b>{"Order " + order.po_number}</b> <Form.Item name="carrIEr" label="carrIEr" initialValue={order.carrIEr}> <input style={{ wIDth: "500px" }} /> </Form.Item> <Form.Item name="po_number" label="PO number" initialValue={order.po_number} hIDden > <input /> </Form.Item> <b>Order Items</b> <Form.List name="items" initialValue={iteminputs}> {(fIElds,{ add,remove }) => ( <> {fIElds.map((fIEld) => ( <Space key={fIEld.key} style={{ display: "flex",marginBottom: 8 }} align="baseline" > <Form.Item {...fIElD} name={[fIEld.name,"item_code"]} fIEldKey={[fIEld.fIEldKey,"item_code"]} > <input placeholder="Item Code" /> </Form.Item> <Form.Item {...fIElD} name={[fIEld.name,"quantity"]} fIEldKey={[fIEld.fIEldKey,"quantity"]} > <input placeholder="Quantity" /> </Form.Item> <Form.Item {...fIElD} name={[fIEld.name,"special_requirements"]} fIEldKey={[fIEld.fIEldKey,"special_requirements"]} > <input placeholder="Quantity" /> </Form.Item> <MinusCircLeoutlined onClick={() => remove(fIEld.Name)} /> </Space> ))} <Form.Item> <button type="dashed" onClick={() => add()} block icon={<PlusOutlined />} > Add item </button> </Form.Item> </> )} </Form.List> <Form.Item> <button type="priMary" HTMLType="submit"> {" "} Change Details{" "} </button> </Form.Item> </Form> </div> ); }; export default GroupForm; //I want to submit a form object that looks like this. E.g. This is what 'onFinish' should display in the console /* { po_number:"123abc",carrIEr:"Fastway",items: [{ item_code:"dnh75n",quantity:"10",special_requirements:"Add picture of happy dog" },{ item_code:"456def",quantity:"4",special_requirements:"Do not include lIDs" } ] } */ 文件发送以使用 actix-web 下载

到目前为止我有:

qrcode

其中包含二维码。我可以使用它的 png 方法将其保存到文件中。但理想情况下,我不会承担这些开销,而是立即发送文件。但是我未能将正确的数据传递给 let qr = QrCode::new(&format!("http://example.com/{}",&link_ID)).unwrap(); let png: ImageBuffer<Luma<u8>,Vec<u8>> = qr.render::<Luma<u8>>().build();

我尝试了以下编译但只发送了无法查看的错误图像:

.save()

解决方法

像这样:

    let qr = QrCode::new("http://example.com/xyz").unwrap();
    let png: ImageBuffer<Luma<u8>,Vec<u8>> = qr.render::<Luma<u8>>().build();
    let mut w = cursor::new(Vec::new());
    DynamicImage::ImageLuma8(png)
        .write_to(&mut w,ImageOutputFormat::Png)
        .unwrap();
    let vec = w.into_inner();
    // vec now contains the PNG bytes

大佬总结

以上是大佬教程为你收集整理的如何从 image::ImageBuffer 到 actix_web::HttpResponse全部内容,希望文章能够帮你解决如何从 image::ImageBuffer 到 actix_web::HttpResponse所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:如何从