Comments (12)
The new version has been released. I will close this issue for now. If there are any problems, just reopen it.
from clipboard-rs.
@whwanyt
Sorry, what I am testing here is the screenshot scene. What is your scene? Copy image files directly?
from clipboard-rs.
Maybe I am not compatible with all image formats, you can provide
- Before get_image(), print available_formats()
- How do you copy the picture?
from clipboard-rs.
@ChurchTao I will reply to the code result at night because I am not in front of the computer right now.
from clipboard-rs.
@whwanyt
OK, I'm waiting for your news.
from clipboard-rs.
I may have guessed your problem. If you use the image.rs
demo to run, you need to change the file saving path
to the path in your own
operating system.
Like
const TMP_PATH: &str = "C:\\Windows\\Temp\\test.png";
I optimized the demo code so that it can run directly in Windows. You can take a look.
8058263#diff-7bf759a09f1216d26074fca12a9e8a2aac8ca2d0392e34ed84fa6974d988aa9bR3
from clipboard-rs.
I used the following sample code to get the clipboard picture and convert it to a base64 character string:
use base64::{engine::general_purpose, Engine as _};
use clipboard_rs::{common::RustImage, Clipboard, ClipboardContext};
fn main() {
let ctx = ClipboardContext::new().unwrap();
let image = ctx.get_image().unwrap();
match image.to_png() {
Ok(res) => {
let image_bytes = res.get_bytes();
let base64_str = general_purpose::STANDARD_NO_PAD.encode(&image_bytes);
println!("{}", base64_str);
}
Err(e) => {
println!("err: {}", e)
}
}
}
The output is as follows:
err: image is empty
I use electron _ screenshot this plugin to achieve screenshots to the clipboard
from clipboard-rs.
I may have guessed your problem. If you use the
image.rs
demo to run, you need to change the filesaving path
to the path in yourown
operating system. Likeconst TMP_PATH: &str = "C:\\Windows\\Temp\\test.png";I optimized the demo code so that it can run directly in Windows. You can take a look.
8058263#diff-7bf759a09f1216d26074fca12a9e8a2aac8ca2d0392e34ed84fa6974d988aa9bR3
Thank you for your reply, my goal is to get the image of the screen captured using the plugin by get_image method and convert it to base64 format
from clipboard-rs.
@whwanyt
Before calling get_image, print available_formats to show me.
from clipboard-rs.
@whwanyt Before calling get_image, print available_formats to show me.
use clipboard_rs::{Clipboard, ClipboardContext};
fn main() {
let ctx = ClipboardContext::new().unwrap();
let types = ctx.available_formats().unwrap();
println!("{:?}", types);
}
The print type results are as follows
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
Running `target\debug\imgdemo.exe`
["CF_BITMAP", "CF_DIB", "CF_DIBV5"]
from clipboard-rs.
@whwanyt
I understand. Sure enough, I am not compatible with images in bitmap format. I will fix it in the next version.
from clipboard-rs.
@whwanyt
Good news, I have solved the compatibility problem. Can you please try the code of this new branch again?
https://github.com/ChurchTao/clipboard-rs/tree/dev-watcher-api-change
from clipboard-rs.
Related Issues (20)
- Abnormal exit HOT 4
- `get_files` Segmentation Fault when there is no files on clipboard HOT 1
- ClipboardContext 能否实现 Clone / Copy ? HOT 5
- Error: `The image format could not be determined` on Win11 HOT 2
- Bug: Cannot paste after writing image to clipboard (on Windows) HOT 2
- Bug: No transparent background for clipboard image read on Windows HOT 1
- Bug: Cannot read clipboard image on MacOS for screenshots taken by certain apps HOT 3
- `set_html()` doesn't update text. HOT 1
- 当写入html时,在Windows上长度似乎是有限制的,并且会被自动截断。截断的长度不固定 HOT 1
- 如何计算图像的哈希值? HOT 6
- 如何获取复制内容的 app 来源 HOT 9
- 在微信选中文字就会触发 `on_clipboard_change` HOT 4
- 重新复制 HTML 时,部分软件粘贴失效 HOT 15
- 如何触发富文本的复制 HOT 17
- linux 下 get_files()一直拿不到结果 HOT 8
- [bug] windows 系统 html 写入剪切板的问题 HOT 12
- 设置剪切板时图片失真,像素偏移 HOT 16
- 部分应用中复制时会触发两次on_clipboard_change HOT 4
- [bug] windows 复制内容频繁崩溃 HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clipboard-rs.