Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging image quality
    primarykey
    data
    text
    <p>I'm trying to create remote control application in Java. I'm using robot to capture my screen image, and then I need to send it to the server. However, because the image size may be too big for the sending to be quick as possible, I'm changing the image quality in the code.</p> <p>The problem is with the code I have, after changing the image it automatically save it as file in my computer but I don't want it to. I want it to the change it without saving it to be able to send it to my server</p> <p>The code:</p> <pre><code>Robot robot = null; Rectangle rectangle = null; GraphicsEnvironment gEnv=GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gDev=gEnv.getDefaultScreenDevice(); //Get screen dimensions Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); rectangle = new Rectangle(dim); System.out.println(rectangle); robot = new Robot(gDev); BufferedImage image = robot.createScreenCapture(rectangle); // FileInputStream inputStream = new FileInputStream(MyFile); // BufferedImage originalImage = ImageIO.read(inputStream); Iterator iter = ImageIO.getImageWritersByFormatName("jpeg"); ImageWriter writer = (ImageWriter)iter.next(); ImageWriteParam iwp = writer.getDefaultWriteParam(); iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); float quality = 0.25f; // reduce quality by 50% iwp.setCompressionQuality(quality); File file = new File("Tester6.png"); FileImageOutputStream output = new FileImageOutputStream(file); writer.setOutput(output); IIOImage image1 = new IIOImage(image, null, null); writer.write(null, image1, iwp); writer.dispose(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload