Hey i write a programm that takes screenshots of the whole screen and searches for special RGB but the .getRed .getBlue ... Methodes are very slow so i heard if i convert the buffered to a byte arry and then search there for the special color is much faster so my question is how can i check this byte for the special RGB and how can i convert the BufferedImage to the Byte ??
Here my Code:
But when i try this with a loaded 1 Pixel .png i get ervery time i run the methode different outputs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Robot; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import javax.imageio.ImageIO; import java.io.File; public class Algorythmus { static Robot Robo; static byte [] data; public static void test() { try { Robo = new Robot(); BufferedImage originalImage = Robo.createScreenCapture( null ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, "png" , baos ); data = baos.toByteArray(); System.out.println(data); } catch (Exception e) { } } } |