Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Java
You last visited: Today at 05:08

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Java]Pixelsearch

Discussion on [Java]Pixelsearch within the Java forum part of the Coders Den category.

Reply
 
Old   #1
 
xXKonaXx's Avatar
 
elite*gold: 20
Join Date: Nov 2010
Posts: 552
Received Thanks: 350
[Java]Pixelsearch

Kleine simple Pixelsearch Funktion die einen ausgewählten Bereich auf eine vordefinierte Farbe scannt und dann die Position des Pixels in Form eines "Point" zurückgibt. Ist zwar nicht das Schnellste, aber erfüllt seinen Zweck.

Code:
public static Point pixelSearchArea(String hexColor, Point topLeft, Point bottomRight) throws AWTException{
		
		int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
		int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
	
		int areaWidth = bottomRight.y - topLeft.y;
		int areaHeight = bottomRight.y - topLeft.y;

		Rectangle area = new Rectangle(topLeft.x, topLeft.y, areaWidth, areaHeight);
		
		Color colorColor = Color.decode(hexColor);

		int searchColor = colorColor.getRGB();

		Robot r = new Robot();
		Rectangle screenRect = area;
		BufferedImage bimage = r.createScreenCapture(screenRect);
		int width = bimage.getWidth();
		int height = bimage.getHeight();
		int[] colors = new int[width * height];
		int[] all = bimage.getRGB(0, 0, width, height, colors , 0, width);

		for(int i = 0; i < all.length; i++)
		{
			if (all[i] == searchColor)
			{
				int y = ((i + 1) / width);
				int x = (i) - (y * width);
				return new Point(screenWidth - (screenWidth - topLeft.x) + x,screenHeight - (screenHeight - topLeft.y) + y);
			}
		}

	return null;
	}
xXKonaXx is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
[JAVA Error] Could not create the java virtual machine
07/21/2013 - Technical Support - 10 Replies
Schönen Abend! Leider hat es sich aus einem unerfindlichen Grund ergeben, dass sobald ich die Minecraft.exe starten will die Errormeldung kommt. Die Tips auf Minecraft.net habe ich schon ohne Erfolg befolgt. Hoffe ihr könnt mir weiterhelfen... Mein PC:
recompile Problem (Block.java, item.java)
04/13/2013 - Minecraft - 1 Replies
Guten Morgen liebe Com (: Ich versuche etwas neues in Minecraft.. für mich einzubauen.. neuer Block + das Item dazu, des eingepflanzt werden muss.. wie bei einer Karotte oder einer Kartoffel. Ich zeige euch den Inhalt meiner BlockOnion.java package net.minecraft.src;
[Java] Could not create the Java virtual machine
06/22/2011 - Minecraft - 1 Replies
hallo ihr minecraftler ^^ habe seit heute das problem das wenn ich minecraft starte original als auch cracked das diese fehlermeldung kommt: Java virtual machine Launcher Could not create the Java virtual machine



All times are GMT +2. The time now is 05:09.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.