Giter Site home page Giter Site logo

Comments (12)

ChurchTao avatar ChurchTao commented on August 21, 2024 1

The new version has been released. I will close this issue for now. If there are any problems, just reopen it.

from clipboard-rs.

ChurchTao avatar ChurchTao commented on August 21, 2024

@whwanyt
Sorry, what I am testing here is the screenshot scene. What is your scene? Copy image files directly?

from clipboard-rs.

ChurchTao avatar ChurchTao commented on August 21, 2024

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.

whwanyt avatar whwanyt commented on August 21, 2024

@ChurchTao I will reply to the code result at night because I am not in front of the computer right now.

from clipboard-rs.

ChurchTao avatar ChurchTao commented on August 21, 2024

@whwanyt
OK, I'm waiting for your news.

from clipboard-rs.

ChurchTao avatar ChurchTao commented on August 21, 2024

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.

whwanyt avatar whwanyt commented on August 21, 2024

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.

whwanyt avatar whwanyt commented on August 21, 2024

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

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.

ChurchTao avatar ChurchTao commented on August 21, 2024

@whwanyt
Before calling get_image, print available_formats to show me.

from clipboard-rs.

whwanyt avatar whwanyt commented on August 21, 2024

@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.

ChurchTao avatar ChurchTao commented on August 21, 2024

@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.

ChurchTao avatar ChurchTao commented on August 21, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.