Print captured image

edited November 2015 in Programming Questions

I want to print captured image, which i grab using get().

As i press button on screen, program capture predefined image, save it & print it.

to save image , i am using save image function & working perfect, but same item how can i send directly print command to default printer.

Need help.

Tagged:

Answers

  • operating system?

    the answer will differ wildly depending on whether you're using windows or a mac or linux.

  • I will use windows7 or 8

  • edited December 2015

    I cannot test on windows at the moment, but i think i've done this kind of things with something similiar to this:

    String commandToRun = "mspaint /pt test.png";
    
    void setup() {
       size(400, 400);
    }
    
    void draw() {
      // draw something
      ellipse(random(width), random(height), 20, 20);
    }
    
    void mousePressed() {
      // save the file
      saveFrame("test.png");
    
      // folder where your image-file is located
      File workingDir = new File(sketchPath(""));      
    
      try {
        // run command
        Process p = Runtime.getRuntime().exec(commandToRun, null, workingDir);
      }
      catch(IOException e) {
        println(e);
      }
    }
    

    edit: There was an error in the code, thanks to @GoToLoop for pointing it out.

  • Thanks Dear Benja, going to test it.

  • Answer ✓

    @benja, don't access sketchPath, width & height before setup().
    It won't work b/c they're not initialized yet! :|

  • every thing run except print.

    sketch saves png file in sketch dir.

    I have set dir address in Working Dir.

    following error generate.

    java.io.IOException: Cannot run program "mspaint" (in directory "sketch_151202a"): CreateProcess error=267, The directory name is invalid

    My working folder is

    D:\Myprocess\sketch_151202a

  • Answer ✓

    Of course @GoToLoop is right, I will change the code above.
    When i move the line with the working-directory to the mousePressed()-function it works for me on Windows7.
    Do you have mspaint installed? You could check by writing "mspaint" in commandline.

  • Yes, it is installed.

    Now working fine.

Sign In or Register to comment.