AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-249900

J. Martin's questions

Martin Hope
J. Martin
Asked: 2024-04-05 10:16:51 +0800 CST

在 Rust 中编辑图像的不透明度

  • 5

我正在尝试循环遍历图像目录,将不透明度编辑为 50%,然后保存它们。我有一组 jpg 和 png 图像。我正在使用图像箱。

可能我必须对图像的格式进行一些考虑,但我不知道是什么......

use clap::Parser;
use std::{process, thread};
#[derive(Parser,Debug)]
#[command(author,version,about,long_about=None)]
struct Args {
    #[arg(long,value_hint=clap::ValueHint::DirPath, default_value="./")]
    picture_dir: std::path::PathBuf,
    #[arg(long, default_value="300")]
    draw_time: u64,
    #[arg(long, default_value="3")]
    start_delay: u64,
    #[arg(long)]
    dry_run: bool,
}


fn main() {
    let args = Args::parse();
    println!("{}", args.picture_dir.as_os_str().to_str().unwrap());
    let dir = args.picture_dir.as_os_str().to_str().unwrap();
    let dir = format!("{}/*.*", dir);
    let extensions_supported = vec!("png","jpg","bmp");
    for path in glob::glob(&dir).expect("Failed to list directory") {
        let path = path.unwrap();
        let copy_from_path = path.clone();
        let file_name = path.file_name().unwrap();
        let mut cachepath = std::env::temp_dir();
        cachepath.push(file_name.to_str().unwrap());
        let str_path = cachepath.to_str().unwrap();
        let path_extension = path.extension().unwrap().to_str().unwrap();
        if !extensions_supported.contains(&path_extension) {
            println!("We don't support that file type");
            continue;
        }
        println!("{}", str_path);
        let start = std::time::Instant::now();
        // We should open the program
        let cmd_str = format!("cmd.exe /C clipstudiopaint.exe {}", str_path);
        let mut child: Option<process::Child> = None;
        if args.dry_run {
            println!("{}",cmd_str);
        } else {
            std::fs::copy(copy_from_path,cachepath.clone()).expect("Failed to create temporary file");
            let cache_image_path = cachepath.clone();
            let cache_image_path = cache_image_path.to_str().unwrap();
            let save_image_path = cachepath.clone();
            let mut image = image::open(cache_image_path)
            .expect("Failed to open image for editing").to_rgba32f();
            image.pixels_mut().for_each(|p| p[3] /= 2.0);
            
            image.save(save_image_path.to_str().unwrap()).expect("Failed to save image");
            //let mut image_target = image::ImageBuffer::new(image.width(), image.height());
            child = Some(process::Command::new("cmd")
            .arg("/C")
            .arg("clipstudiopaint.exe")
            .arg(cachepath.to_str().unwrap())
            .spawn()
            .expect("Failed to run clipstudiopaint"));
        }
        // We should wait a couple of seconds for it to load
        loop {
            if start.elapsed().as_secs() > args.start_delay {
                break;
            }
        }
        let start = std::time::Instant::now();
        // we should wait the specified drawing time
        println!("Starting timer");
        loop {
            if start.elapsed().as_secs() > args.draw_time {
                break;
            }
        }   
        // we should kill the process
        if !args.dry_run {
            child.unwrap().kill().expect("Failed to kill childprocess");
            std::fs::remove_file(cachepath).expect("Failed to remove temp file");
        }
        let start = std::time::Instant::now();
        loop {
            if start.elapsed().as_secs() > 2 {
                break;
            }
        }  
    }
}

这会导致错误:Failed to save image: Encoding(EncodingError { format: Exact(Png), underlying: Some(ColorType(Rgba32F)) })

最终答案的相关部分最终如下所示:

std::fs::copy(copy_from_path,cachepath.clone()).expect("Failed to create temporary file");
let image_edit_path = image_edit_path.clone();
let image_edit_path = image_edit_path.to_str().unwrap();
let save_image_path = cachepath.clone();
println!("Opening: {} for editing", image_edit_path);
let mut image = image::open(image_edit_path)
.expect("Failed to open image for editing");
let mut target_image = image::DynamicImage::new_rgba8(image.width(), image.height());
let mut target_image = target_image.to_rgba8();
target_image.pixels_mut().for_each(|p| *p = image::Rgba{0: [246, 244, 237, 255]});
let mut image = image.to_rgba8();
image.pixels_mut().for_each(|p| p[3] = 100);
image::imageops::overlay(&mut target_image, &image, 0, 0);
let target_image = image::DynamicImage::ImageRgba8(target_image);

target_image.save(save_image_path.to_str().unwrap()).expect("Failed to save image");
image
  • 1 个回答
  • 27 Views
Martin Hope
J. Martin
Asked: 2023-11-27 11:59:09 +0800 CST

EXCEL INDIRECT 返回奇怪的值

  • 5

我有两张表,一张名为 Spread,一张名为 TSN。

在“传播”上,我想显示 TSN!A2 中出现的值:11/24/2023

如果我将公式 =TSN!A2 输入 Spread!A2 中,我会得到预期值。

如果我将 TSN 值放入 Spread!A1,然后将公式: ==INDIRECT( "'" & $A1 &"'!A2" ) 放入 Spread!A2,我得到的值是 45254。我没有得到错误。只是一个奇怪的值。TSN 上没有提及 45254...

我希望人们能够在单元格 Spread!A1 中输入工作表的名称,并让它填充目标工作表中的数据...

我是一名 excel n00b,所以显然我做错了。我尝试过 INDIRECT 的一些变体,所有变体都会产生相同的值。

编辑:

TSN!B2 的值为 47.529。如果我将间接调用更改为拉入 B2 而不是 A2,它将获得正确的值。这是否意味着 TSN 中 A2 的潜在价值实际上是某种隐藏的时间价值?

excel-formula
  • 1 个回答
  • 21 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve